Skip to content

When the x11 server crashes, loop connection.wait_for_event will occupy 100% of a single cpu core #93

Description

@I-Want-ToBelieve

wait_for_event should return an error when the x11 server crashes, so that the program can catch the error instead of entering an infinite loop

use breadx::{display::DisplayConnection, prelude::*};

fn main() {
    /*
     * @see https://docs.rs/breadx/3.1.0/breadx/
     */
    let mut connection = DisplayConnection::connect(None).expect("should connect to x11 server");

    /*
     * @see https://gist.github.com/ssokolow/e7c9aae63fb7973e4d64cff969a78ae8
     */

    // primary event loop
    loop {
        let event = connection.wait_for_event();

        match event {
            Err(_) => {
                eprintln!("X11 server has crashed, exiting program.");
                std::process::exit(1);
            }
            Ok(_) => todo!(),
        }
    }
}

I've prepared a minimal repo that can easily reproduce the issue

git clone https://github.com/I-Want-ToBelieve/autohide-tdrop.git
git checkout bug/infinite-loop 
cargo run
pkill -f Xwayland

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions