Desktop: no exceptions when servers report leaving after shutdown

Quitting from the shutdown hook (SIGTERM) leaves every server, whose
disconnects then reach the mic hand-over and the notifier after their
threads have stopped. Both now drop work that comes in that late.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 20:30:11 +00:00
co-authored by Claude Opus 5.5
parent e9110c2767
commit 0043c03410
2 changed files with 32 additions and 7 deletions
@@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionException;
/**
* Every server the client is on, and what they share. Only one of them can capture with the
@@ -73,7 +74,7 @@ public final class Sessions {
if (microphoneOwner == session) return;
ServerSession previous = microphoneOwner;
microphoneOwner = session;
handover.execute(() -> {
handOver(() -> {
if (previous != null) previous.setMicrophoneActive(false);
if (session != null) session.setMicrophoneActive(true);
});
@@ -105,7 +106,7 @@ public final class Sessions {
public void disconnected(ServerSession session) {
if (microphoneOwner == session) {
microphoneOwner = null;
handover.execute(() -> session.setMicrophoneActive(false));
handOver(() -> session.setMicrophoneActive(false));
}
assignMicrophoneIfFree();
}
@@ -134,6 +135,18 @@ public final class Sessions {
return session == null || !session.isConnected() ? null : session.microphone();
}
/**
* Runs a hand-over on {@link #handover}. Leaving every server on {@link #shutdown} reports
* each disconnect to the frontend, which may pass it on here after the thread is gone;
* with every server left, there is nothing to hand over.
*/
private void handOver(Runnable change) {
try {
handover.execute(change);
} catch (RejectedExecutionException ignored) {
}
}
// ---- the user's own state ----
public void setAwayEverywhere(boolean away, String message) {