fix(wm): add cmd thread lock acquisition timeouts

After some investigation by @alex-ds13 on Discord it looks like there
are times where attempting to gain a lock on the WindowManager inside of
read_commands_uds results in the thread becoming blocked when it's not
possible to obtain the lock.

Instead of waiting indefinitely for a lock, this change ensures that we
will wait for at most 1 second before discarding the message so that the
command listener loop can continue.

Warning logs have been added to inform when a message has been dropped
as a result of lock acquisition failure.
This commit is contained in:
LGUG2Z
2024-10-13 14:41:46 -07:00
parent 1376d7be04
commit b0944662fa

View File

@@ -1619,22 +1619,29 @@ pub fn read_commands_uds(wm: &Arc<Mutex<WindowManager>>, mut stream: UnixStream)
for line in reader.lines() { for line in reader.lines() {
let message = SocketMessage::from_str(&line?)?; let message = SocketMessage::from_str(&line?)?;
let mut wm = wm.lock(); match wm.try_lock_for(Duration::from_secs(1)) {
None => {
if wm.is_paused { tracing::warn!(
return match message { "could not acquire window manager lock, not processing message: {message}"
SocketMessage::TogglePause );
| SocketMessage::State }
| SocketMessage::GlobalState Some(mut wm) => {
| SocketMessage::Stop => Ok(wm.process_command(message, &mut stream)?), if wm.is_paused {
_ => { return match message {
tracing::trace!("ignoring while paused"); SocketMessage::TogglePause
Ok(()) | SocketMessage::State
| SocketMessage::GlobalState
| SocketMessage::Stop => Ok(wm.process_command(message, &mut stream)?),
_ => {
tracing::trace!("ignoring while paused");
Ok(())
}
};
} }
};
}
wm.process_command(message.clone(), &mut stream)?; wm.process_command(message.clone(), &mut stream)?;
}
}
} }
Ok(()) Ok(())