From e12b90991c3784552e048d7561bd4e9a27716adb Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 19 May 2024 01:55:58 +0000 Subject: [PATCH] fix(iroh-gossip): do not drop existing peer connection when we get incoming one --- iroh-gossip/src/net.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/iroh-gossip/src/net.rs b/iroh-gossip/src/net.rs index 97f554cda7..4083e3a113 100644 --- a/iroh-gossip/src/net.rs +++ b/iroh-gossip/src/net.rs @@ -615,11 +615,13 @@ async fn connection_loop( loop { tokio::select! { biased; - msg = send_rx.recv() => { - match msg { - None => break, - Some(msg) => write_message(&mut send, &mut send_buf, &msg).await?, - } + // If `send_rx` is closed, + // stop selecting it but don't quit. + // We are not going to use connection for sending anymore, + // but the other side may still want to use it to + // send data to us. + Some(msg) = send_rx.recv(), if !send_rx.is_closed() => { + write_message(&mut send, &mut send_buf, &msg).await? } msg = read_message(&mut recv, &mut recv_buf) => {