Skip to content

Commit

Permalink
fix(wm): restart cmd listener thread on panic
Browse files Browse the repository at this point in the history
This commit ensures that in the event of a panic (we still have quite a
few that occur sporadically that are still being tracked down), the
listen_for_commands thread in process_command is restarted, similarly to
the recently added border, stackbar and transparency manager threads.

In order to do this without blocking the process startup sequence,
listen_for_commands spawns an outer thread which begins a loop in which
the actual command listener thread is started.

We call .join() on the handle of this inner thread, and log an error
whenever that inner thread terminates, as it should never terminate
unless there is a panic.

If the inner thread is terminated due to a panic, the outer loop will
start another thread to ensure that user commands continue being
processed.

One thing to note is that panics may lead to an inconsistent wm state
and undefined behaviour which will seem "new", as previously these
panics required a total restart of komorebi and any inconsistent states
would be masked.
  • Loading branch information
LGUG2Z committed Jun 5, 2024
1 parent 133311b commit edc87d9
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,33 @@ use stackbar_manager::STACKBAR_UNFOCUSED_TEXT_COLOUR;

#[tracing::instrument]
pub fn listen_for_commands(wm: Arc<Mutex<WindowManager>>) {
let listener = wm
.lock()
.command_listener
.try_clone()
.expect("could not clone unix listener");

std::thread::spawn(move || {
tracing::info!("listening on komorebi.sock");
for client in listener.incoming() {
match client {
Ok(stream) => match read_commands_uds(&wm, stream) {
Ok(()) => {}
Err(error) => tracing::error!("{}", error),
},
Err(error) => {
tracing::error!("{}", error);
break;
std::thread::spawn(move || loop {
let wm = wm.clone();

let _ = std::thread::spawn(move || {
let listener = wm
.lock()
.command_listener
.try_clone()
.expect("could not clone unix listener");

tracing::info!("listening on komorebi.sock");
for client in listener.incoming() {
match client {
Ok(stream) => match read_commands_uds(&wm, stream) {
Ok(()) => {}
Err(error) => tracing::error!("{}", error),
},
Err(error) => {
tracing::error!("{}", error);
break;
}
}
}
}
})
.join();

tracing::error!("restarting failed thread");
});
}

Expand Down

0 comments on commit edc87d9

Please sign in to comment.