Skip to content

Commit 78d934f

Browse files
authored
multistream: Do not wait for negotiation in poll_close (#319)
This PR backports https://github.com/libp2p/rust-libp2p/pull/4019/files, effectively ensuring that our `poll_close` flushes any data immediately without waiting for negotiation to complete. Closes an outdated PR: #62 cc @paritytech/networking --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
1 parent 2412f3d commit 78d934f

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/multistream_select/dialer_select.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,7 @@ mod tests {
548548
io.close().await.unwrap();
549549
});
550550

551-
// TODO: Once https://github.com/paritytech/litep2p/pull/62 is merged, this
552-
// should be changed to `is_ok`.
553-
assert!(tokio::time::timeout(Duration::from_secs(10), client).await.is_err());
551+
assert!(tokio::time::timeout(Duration::from_secs(10), client).await.is_ok());
554552
}
555553

556554
#[tokio::test]

src/multistream_select/negotiated.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,15 +323,22 @@ where
323323
}
324324

325325
fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
326-
// Ensure all data has been flushed and expected negotiation messages
327-
// have been received.
328-
ready!(self.as_mut().poll(cx).map_err(Into::<io::Error>::into)?);
326+
// Ensure all data has been flushed, including optimistic multistream-select messages.
329327
ready!(self.as_mut().poll_flush(cx).map_err(Into::<io::Error>::into)?);
330328

331329
// Continue with the shutdown of the underlying I/O stream.
332330
match self.project().state.project() {
333331
StateProj::Completed { io, .. } => io.poll_close(cx),
334-
StateProj::Expecting { io, .. } => io.poll_close(cx),
332+
StateProj::Expecting { io, .. } => {
333+
let close_poll = io.poll_close(cx);
334+
if let Poll::Ready(Ok(())) = close_poll {
335+
tracing::debug!(
336+
target: LOG_TARGET,
337+
"Stream closed. Confirmation from remote for optimstic protocol negotiation still pending."
338+
);
339+
}
340+
close_poll
341+
}
335342
StateProj::Invalid => panic!("Negotiated: Invalid state"),
336343
}
337344
}

0 commit comments

Comments
 (0)