Skip to content

Commit ccdb399

Browse files
EddieHoustonphilippem
authored andcommitted
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
1 parent 69fcfc5 commit ccdb399

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/electrum/server.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,11 @@ impl RPC {
766766
}
767767
})
768768
}
769-
Notification::Exit => acceptor.send(None).unwrap(), // mark acceptor as done
769+
Notification::Exit => {
770+
if acceptor.send(None).is_err() {
771+
warn!("acceptor already shut down before Exit notification");
772+
}
773+
}
770774
}
771775
}
772776
});
@@ -789,7 +793,9 @@ impl RPC {
789793
stream
790794
.set_nonblocking(false)
791795
.expect("failed to set connection as blocking");
792-
acceptor.send(Some((stream, addr))).expect("send failed");
796+
if acceptor.send(Some((stream, addr))).is_err() {
797+
break; // receiver dropped, server is shutting down
798+
}
793799
}
794800
});
795801
chan

0 commit comments

Comments
 (0)