Repository navigation
fix(pipe): preserve websocket bytes after upgrade - #1288
Merged
Merged
Conversation
When a backend sends a WebSocket 101 response and the first frame in the same TCP read, the H1 mux can parse the headers while leaving post-upgrade bytes in Kawa's remaining buffer window. Sync that window before handing the connection to Pipe, then arm writable readiness for any inherited direction buffers so edge-triggered epoll flushes them immediately. Add an e2e regression for a same-buffer 101 plus WebSocket text frame. Signed-off-by: Florentin Dubois <[email protected]>
Collapse two nested conditionals that Rust 1.91 clippy rejects when running the repository pre-push all-features gate. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
marked this pull request as ready for review
July 8, 2026 10:21
FlorentinDUBOIS
commented
Jul 8, 2026
FlorentinDUBOIS
left a comment
Collaborator
Author
There was a problem hiding this comment.
Automated cross-review (review / review-code / guidelines / simplify / security-review + Codex). One finding inline; comments batched into one review. GitHub does not allow the PR author account to request changes on its own PR, so this is submitted as a comment review.
Restore the mux readiness events through a Pipe helper that re-arms writable readiness for buffers already inherited at upgrade time. This prevents the HTTP and HTTPS upgrade handoffs from erasing the synthetic writable event needed to flush bytes that were exposed by the mux buffer sync. Add a pipe regression covering event restore with inherited frontend and backend buffered bytes. Signed-off-by: Florentin Dubois <[email protected]>
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.
Summary
101 Switching Protocolsresponse.Pipe::restore_readiness_events(...)so already-buffered bytes keep a writable event after HTTP/HTTPS handoff restores mux readiness.101response and the first WebSocket text frame.Root Cause
The H1 mux returned
SessionResult::Upgradewithout syncing Kawa's remaining post-header bytes back into theCheckoutbuffer window. When the backend sent101 Switching Protocolsand the first WebSocket frame in the same TCP segment, the pipe inherited a buffer whose readable window did not expose the post-101bytes.The first fix also needed one follow-up: HTTP and HTTPS restore the pre-upgrade mux readiness events after constructing the
Pipe, so any syntheticWRITABLEevent set duringPipe::new()could be erased.Pipe::restore_readiness_events(...)now performs that restore and then re-arms writable readiness for inherited frontend/backend buffers.User Impact
This fixes WebSocket backends such as Reverb, Soketi, and Pusher-compatible servers that send
connection_establishedimmediately after the upgrade response. The first frame is now forwarded even when it shares the same backend read buffer as the101response.Review Follow-Up
Addressed the inline review on
lib/src/protocol/pipe.rsby moving the inherited-event restore behind aPipehelper that re-arms buffered writes after the restore. The newrestore_readiness_events_rearms_inherited_buffered_writesregression was observed red before the re-arm and green after the fix.Validation
cargo test -p sozu-lib restore_readiness_events_rearms_inherited_buffered_writes --lockedcargo test -p sozu-lib protocol::pipe --lockedcargo test -p sozu-e2e test_websocket_backend_frame_in_same_read_as_101 --lockedcargo test -p sozu-e2e websocket --lockedcargo +nightly fmt --all -- --checkcargo build --all-features --lockedcargo clippy --all-targets --locked -- -D warningscargo test --workspace --lockedcargo clippy --all-features --all-targets --locked -- -D warningsgit diff --check