From 710812f5a8a7985441a04bfbaaeb346bf1551cd4 Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 26 Apr 2023 06:05:37 +1000 Subject: [PATCH] Avoid a rare panic when a connection is dropped --- zebra-network/src/peer/client.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/zebra-network/src/peer/client.rs b/zebra-network/src/peer/client.rs index 68e694618f8..3b6e0fcdc78 100644 --- a/zebra-network/src/peer/client.rs +++ b/zebra-network/src/peer/client.rs @@ -621,8 +621,13 @@ impl Service for Client { Ok(()) => { // The receiver end of the oneshot is itself a future. rx.map(|oneshot_recv_result| { - oneshot_recv_result - .expect("ClientRequest oneshot sender must not be dropped before send") + // The ClientRequest oneshot sender should not be dropped before sending a + // response. But sometimes that happens during process or connection shutdown. + // So we just return a generic error here. + match oneshot_recv_result { + Ok(result) => result, + Err(oneshot::Canceled) => Err(PeerError::ConnectionDropped.into()), + } }) .boxed() }