[libp2p-ping] Properly close the substream in the InboundUpgrade. (#1606)

Not doing so may result in FIN/RST frames being sent before
earlier data frames. See https://github.com/paritytech/yamux/pull/81#issuecomment-643169973.
This commit is contained in:
Roman Borschel
2020-06-12 17:41:04 +02:00
committed by GitHub
parent 9aaf042410
commit e8bf34fcf1

View File

@ -69,6 +69,7 @@ where
while let Ok(_) = socket.read_exact(&mut payload).await { while let Ok(_) = socket.read_exact(&mut payload).await {
socket.write_all(&payload).await?; socket.write_all(&payload).await?;
} }
socket.close().await?;
Ok(()) Ok(())
}.boxed() }.boxed()
} }
@ -128,7 +129,7 @@ mod tests {
} else { } else {
panic!("MemoryTransport not listening on an address!"); panic!("MemoryTransport not listening on an address!");
}; };
async_std::task::spawn(async move { async_std::task::spawn(async move {
let listener_event = listener.next().await.unwrap(); let listener_event = listener.next().await.unwrap();
let (listener_upgrade, _) = listener_event.unwrap().into_upgrade().unwrap(); let (listener_upgrade, _) = listener_event.unwrap().into_upgrade().unwrap();