From 4a41c9254ddcfae218a77d382cdc3fb336d3acec Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Tue, 21 Jul 2020 23:56:06 -0700 Subject: [PATCH] network: avoid panic when shutting down cleanly. When the connection sees the client_rx channel close it knows it will never get any more requests, and it should terminate. But instead of terminating, it errored itself, and the method to error itself tries to pull all the outstanding client requests from the channel in order to fail them before it shuts down. This results in reading from a closed channel, causing a panic. Instead we return cleanly rather than failing (since we know there are no outstanding requests, as the channel is closed). --- zebra-network/src/peer/connection.rs | 3 ++- zebra-network/src/peer/error.rs | 4 ---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/zebra-network/src/peer/connection.rs b/zebra-network/src/peer/connection.rs index a4dc892da..1bb8d2f24 100644 --- a/zebra-network/src/peer/connection.rs +++ b/zebra-network/src/peer/connection.rs @@ -190,7 +190,8 @@ where self.handle_message_as_request(msg).await } Either::Right((None, _)) => { - self.fail_with(PeerError::DeadClient); + trace!("client_rx closed, ending connection"); + return; } Either::Right((Some(req), _)) => { let span = req.span.clone(); diff --git a/zebra-network/src/peer/error.rs b/zebra-network/src/peer/error.rs index 82b2a3eaa..7fe7e5355 100644 --- a/zebra-network/src/peer/error.rs +++ b/zebra-network/src/peer/error.rs @@ -26,10 +26,6 @@ pub enum PeerError { /// The remote peer closed the connection. #[error("Peer closed connection")] ConnectionClosed, - /// The [`peer::Client`] half of the [`peer::Client`]/[`peer::Server`] pair died before - /// the [`Server`] half did. - #[error("peer::Client instance died")] - DeadClient, /// The remote peer did not respond to a [`peer::Client`] request in time. #[error("Client request timed out")] ClientRequestTimeout,