From 17651e259dc05f74d9ff8c8530c04a681b1a77d0 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Wed, 12 Apr 2023 16:51:57 +0200 Subject: [PATCH] node: Don't panic if peer disconnected --- radicle-node/src/wire/protocol.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/radicle-node/src/wire/protocol.rs b/radicle-node/src/wire/protocol.rs index 9ec10ba1..d858f41b 100644 --- a/radicle-node/src/wire/protocol.rs +++ b/radicle-node/src/wire/protocol.rs @@ -395,13 +395,14 @@ where } fn flush(&mut self, remote: NodeId, stream: StreamId) { - let (fd, peer) = self + let Some((fd, peer)) = self .peers .iter() .find(|(_, peer)| peer.id() == Some(&remote)) - .map(|(fd, peer)| (*fd, peer)) - .unwrap_or_else(|| panic!("Peer {remote} was expected to be known to the transport")); - + .map(|(fd, peer)| (*fd, peer)) else { + log::warn!(target: "wire", "Peer {remote} is not known; ignoring flush"); + return; + }; let Peer::Connected { streams, link, .. } = peer else { log::warn!(target: "wire", "Peer {remote} is not connected; ignoring flush"); return;