-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix connection flush #130
Fix connection flush #130
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, thank you for digging so deep into this!
src/connection.rs
Outdated
return Poll::Ready(res); | ||
} | ||
|
||
if let Poll::Ready(Err(err)) = socket.poll_flush_unpin(cx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we assume that for all implementations of Sink
poll_flush_unpin
is cheap? If not, we could stop calling poll_flush_unpin
once it returns Poll::Ready(Ok(()))
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense. But we need to make sure to reset every time we write to the underlying IO
Co-authored-by: Max Inden <mail@max-inden.de>
@mxinden Updated. I don't know if you had something else in mind, but it does the trick. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @appaquet. I will prepare a release candidate to test on larger deployments.
See the full conversation here: libp2p/rust-libp2p#2461
The bump to Yamux 0.10 in libp2p broke the wasm-ext transport (used for WebSocket transport in WebAssembly). It turns out that the wasm-ext implementation makes it more prone to yield a
Pending
on apoll_next
(see this). When used in conjunction with Noise, a frame may get buffered and only written to the underlying I/O stream when flushing it (see this)In #112, flushing is no longer awaited, but instead, is called at each iteration of the
next
loop inConnection
(see this). Unfortunately, when using wasm-ext with Noise, frames may never get written until the next iteration is triggered by another event (incoming frame or stream/control events).As discussed in libp2p's issue, a fix is to make sure that flushing the I/O stream gets progressed in the main loop. I also think that
flush_nowait
is not required anymore since flushing is now actively done in the loop.