From f043c73ef7b517ee5866aa972685082a0437f5a0 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 29 Oct 2026 02:17:32 +0100 Subject: libp2p: close QUIC streams cleanly --- src/transport/libp2p.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/transport/libp2p.rs b/src/transport/libp2p.rs index 8746206..b5cee5f 100644 --- a/src/transport/libp2p.rs +++ b/src/transport/libp2p.rs @@ -1918,6 +1918,23 @@ impl Transport for Libp2pTransport { stream.write_all(&(body.len() as u32).to_be_bytes()).await?; stream.write_all(&body).await?; stream.close().await?; + // Kept until the peer has closed its side too. Over QUIC, dropping a stream + // stops its reading half (STOP_SENDING), and the peer's answer to the + // protocol (sent with the first data, `swarm_config`) then fails, and with it + // the stream, before the peer has read the message: identify, which reads + // its answers, works, while every message is lost. Yamux (TCP) doesn't mind. + // Off the send, which is done. + tokio::spawn(async move { + let mut rest = [0u8; 64]; + let _ = tokio::time::timeout(STREAM_TIMEOUT, async { + while let Ok(read) = stream.read(&mut rest).await { + if read == 0 { + break; + } + } + }) + .await; + }); Ok::<_, anyhow::Error>(opened) }; let timeout = stream_timeout(message.body.len()); -- cgit v1.3.1