From e4b15a49d656b3e9799b825466a303793d4ccf09 Mon Sep 17 00:00:00 2001 From: Edward Houston Date: Mon, 20 Apr 2026 14:52:48 +0200 Subject: [PATCH] fix(electrum): handle shutdown race in acceptor thread The 'acceptor' thread panicked with 'send failed' when a TCP connection arrived at the exact moment the server was shutting down. The 'rpc' thread drops the channel receiver upon receiving the Exit notification, leaving the 'acceptor' thread's next send() with no receiver. - Break cleanly from the acceptor loop when the receiver is dropped - Replace unwrap() with a warn! log in the notification thread for the symmetric case where the acceptor has already exited before Exit fires --- src/electrum/server.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/electrum/server.rs b/src/electrum/server.rs index ea5579699..8463b916d 100644 --- a/src/electrum/server.rs +++ b/src/electrum/server.rs @@ -766,7 +766,11 @@ impl RPC { } }) } - Notification::Exit => acceptor.send(None).unwrap(), // mark acceptor as done + Notification::Exit => { + if acceptor.send(None).is_err() { + warn!("acceptor already shut down before Exit notification"); + } + } } } }); @@ -789,7 +793,9 @@ impl RPC { stream .set_nonblocking(false) .expect("failed to set connection as blocking"); - acceptor.send(Some((stream, addr))).expect("send failed"); + if acceptor.send(Some((stream, addr))).is_err() { + break; // receiver dropped, server is shutting down + } } }); chan