Fix frozen client on ctrl+q: send bye instead of half-closing
Dropping the client's channel sender never closed the socket (the server's reader thread keeps the connection open), so the client froze waiting for frames. The server now sends a bye message; the client exits cleanly on it and its socket close lets the server clean up. Messages from already-disconnected clients are ignored. Verified end-to-end with the real client in a PTY (exits 0, daemon survives). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
12
src/main.rs
12
src/main.rs
@@ -438,6 +438,11 @@ fn handle_ipc_event(
|
||||
all_clients.remove(&client_id);
|
||||
}
|
||||
IpcEvent::Message { client_id, msg } => {
|
||||
// Ignorera meddelanden från klienter som redan kopplats ner
|
||||
// (t.ex. efter bye) men vars socket ännu inte hunnit stängas.
|
||||
if !all_clients.contains_key(&client_id) {
|
||||
return;
|
||||
}
|
||||
match msg {
|
||||
ClientMessage::Input { data } => {
|
||||
let bytes = ipc::from_hex(&data);
|
||||
@@ -540,7 +545,12 @@ fn disconnect_instead_of_quit(
|
||||
) {
|
||||
if app.should_quit {
|
||||
app.should_quit = false;
|
||||
// Sändaren droppas → klientens ström stängs → klienten avslutar.
|
||||
// Skicka bye så klienten avslutar och stänger socketen — att bara
|
||||
// droppa sändaren räcker inte, eftersom serverns läsartråd håller
|
||||
// anslutningen öppen och klienten annars fryser i väntan på frames.
|
||||
if let Some((_, _, _, tx)) = all_clients.get(&client_id) {
|
||||
let _ = tx.try_send(ServerMessage::Bye);
|
||||
}
|
||||
all_clients.remove(&client_id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user