mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-26 11:21:20 +01:00
fix(wm): restart cmd listener thread on panic
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.
This commit is contained in:
@@ -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 || loop {
|
||||
let wm = wm.clone();
|
||||
|
||||
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;
|
||||
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");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user