crypto/noise: Improve stability of websockets by fixing AsyncWrite implementation#518
Merged
crypto/noise: Improve stability of websockets by fixing AsyncWrite implementation#518
Conversation
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
dmitry-markin
approved these changes
Jan 20, 2026
Collaborator
dmitry-markin
left a comment
There was a problem hiding this comment.
Cool finding and good job here!
src/crypto/noise/mod.rs
Outdated
| // This can happen once we have pending data and no space to buffer new data. | ||
| // Therefore, a call to poll_write returned Pending in the first step. This | ||
| // just forwards the Pending to the caller until we have space again. | ||
| return Poll::Pending; |
Collaborator
There was a problem hiding this comment.
It looks like we haven't registered the waker to wake up the task once we have space in the buffer (and poll_write above might not wake as as well if it returned Ready). May be we don't need this if block at all to not return Poll::Pending?
Collaborator
Author
There was a problem hiding this comment.
Yep, if the poll_write returns Poll::Ready, then we must rely on the fact that:
- one chunk+overhead has sufficient space to fill into the
encrypt_buffer
2 tasks
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
dmitry-markin
added a commit
that referenced
this pull request
Jan 21, 2026
## [0.13.0] - 2026-01-21 This release brings multiple fixes to both the transport and application-level protocols. Specifically, it enhances WebSocket stability by resolving AsyncWrite errors and ensuring that partial writes during the negotiation phase no longer trigger connection failures. At the same time, Bitswap client functionality is introduced, which makes this release semver breaking. ### Added - Add Bitswap client ([#501](#501)) ### Fixed - notif/fix: Avoid CPU busy loops on litep2p full shutdown ([#521](#521)) - protocol: Ensure transport manager knows about closed connections ([#515](#515)) - substream: Decrement the bytes counter to avoid excessive flushing ([#511](#511)) - crypto/noise: Improve stability of websockets by fixing AsyncWrite implementation ([#518](#518)) - bitswap: Split block responses into batches under 2 MiB ([#516](#516)) - crypto/noise: Fix connection negotiation logic on partial writes ([#519](#519)) - substream/fix: Fix partial reads for ProtocolCodec::Identity ([#512](#512)) - webrtc: Avoid panics returning error instead ([#509](#509)) - bitswap: e2e test & max payload fix ([#508](#508)) - tcp: Exit connections when events fail to propagate to protocols ([#506](#506)) - webrtc: Avoid future being dropped when channel is full ([#483](#483)) --------- Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The PR fixes a
AsyncWrite::poll_writeimplementation of the crypto/noise sockets that causes panics in rust-yamux and leads to unnecessary connection closure and instability:This PR fixes the
AsyncWritecontract violation by effectively decoupling the encryption from the writing steps.Previous fixes:
The fixes are still needed since the tokio-tungstenite (websocket crate) was not properly scoped and may exhibit similar behavior.
cc @paritytech/networking