Skip to content

Commit

Permalink
fix(wm): add cmd thread lock acquisition timeouts
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LGUG2Z committed Oct 13, 2024
1 parent 1376d7b commit b094466
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1619,22 +1619,29 @@ pub fn read_commands_uds(wm: &Arc<Mutex<WindowManager>>, mut stream: UnixStream)
for line in reader.lines() {
let message = SocketMessage::from_str(&line?)?;

let mut wm = wm.lock();

if wm.is_paused {
return match message {
SocketMessage::TogglePause
| SocketMessage::State
| SocketMessage::GlobalState
| SocketMessage::Stop => Ok(wm.process_command(message, &mut stream)?),
_ => {
tracing::trace!("ignoring while paused");
Ok(())
}
};
}
match wm.try_lock_for(Duration::from_secs(1)) {
None => {
tracing::warn!(
"could not acquire window manager lock, not processing message: {message}"
);
}
Some(mut wm) => {
if wm.is_paused {
return match message {
SocketMessage::TogglePause
| 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(())
Expand Down

0 comments on commit b094466

Please sign in to comment.