summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-29 02:17:32 +0100
committertv <tv@krebsco.de>2026-10-29 02:17:32 +0100
commitf043c73ef7b517ee5866aa972685082a0437f5a0 (patch)
treefc739598c215ccdb14e3904f2ec1b3f4422a1d3f /src
parentbc6fb7aa5281a50ff3b1ab8b1deae18e04449e31 (diff)
libp2p: close QUIC streams cleanly
Diffstat (limited to 'src')
-rw-r--r--src/transport/libp2p.rs17
1 files changed, 17 insertions, 0 deletions
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());