Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
I-Want-ToBelieve opened this issue Dec 4, 2023 · 0 comments

Comments

@I-Want-ToBelieve
Copy link

I-Want-ToBelieve commented Dec 4, 2023

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
@I-Want-ToBelieve I-Want-ToBelieve changed the title When the x11 server crashes, connection.wait_for_event will occupy 100% of a single cpu When the x11 server crashes, connection.wait_for_event will occupy 100% of a single cpu core Dec 4, 2023
@I-Want-ToBelieve I-Want-ToBelieve changed the title When the x11 server crashes, connection.wait_for_event will occupy 100% of a single cpu core When the x11 server crashes, loop connection.wait_for_event will occupy 100% of a single cpu core Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant