From 7f0b54c35e932e5fc753d5e24738de7303763dcc Mon Sep 17 00:00:00 2001 From: alex-ds13 <145657253+alex-ds13@users.noreply.github.com> Date: Mon, 11 Nov 2024 12:06:49 +0000 Subject: [PATCH] fix(wm): add read timeout to command socket After investigating further the issue where commands would randomly stop working, we've noticed that the issue seems to be that somehow the listening thread gets stuck reading the unix socket, as in it continuously tries to read a socket on a connection that is not sending anything anymore. The result would be that komorebi would no longer be able to receive commands until it was restarted. This fix adds a read timeout of 1s and it spawns a new thread to handle the stream reading and process of cmds. So in case this happens again, that specific processing thread will only be stuck for 1s but the rest of komorebi will never get stuck and should keep working normally. --- komorebi/src/process_command.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 18fe5661..117b19f0 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -109,10 +109,19 @@ pub fn listen_for_commands(wm: Arc>) { 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), - }, + Ok(stream) => { + let wm_clone = wm.clone(); + std::thread::spawn(move || { + match stream.set_read_timeout(Some(Duration::from_secs(1))) { + Ok(()) => {} + Err(error) => tracing::error!("{}", error), + } + match read_commands_uds(&wm_clone, stream) { + Ok(()) => {} + Err(error) => tracing::error!("{}", error), + } + }); + } Err(error) => { tracing::error!("{}", error); break;