From da8fa7fac8e78fa643a1393b6a6775963e9385b9 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 19 May 2024 01:55:58 +0000 Subject: [PATCH] fix: do not drop existing peer connection when we get incoming one --- iroh-gossip/src/net.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/iroh-gossip/src/net.rs b/iroh-gossip/src/net.rs index ec72f65466e..3219e873c1f 100644 --- a/iroh-gossip/src/net.rs +++ b/iroh-gossip/src/net.rs @@ -433,10 +433,22 @@ impl Actor { // Spawn a task for this connection let in_event_tx = self.in_event_tx.clone(); + + // Clone send_tx and give it to the connection loop + // to prevent the channel from closing. + // Otherwise connection loop will exit as soon as we drop send_tx + // from conn_send_tx map. + // + // We don't want to exit connection loop + // and close the connection just because we don't want to + // use the connection for sending anymore, because the other side + // may still want to use the connection to send data to us. + let send_tx_clone = send_tx.clone(); + tokio::spawn( async move { debug!("connection established"); - match connection_loop(peer_id, conn, origin, send_rx, &in_event_tx).await { + match connection_loop(peer_id, conn, origin, send_tx_clone, send_rx, &in_event_tx).await { Ok(()) => { debug!("connection closed without error") } @@ -607,6 +619,7 @@ async fn connection_loop( from: PublicKey, conn: Connection, origin: ConnOrigin, + _send_tx: mpsc::Sender, mut send_rx: mpsc::Receiver, in_event_tx: &mpsc::Sender, ) -> anyhow::Result<()> {