Repository navigation
Conversation
…st end For a request without a body (a websocket GET), the downstream half queues `Body(None, true)` for the upstream half before the duplex loop starts. If the upstream's 101 is already readable when `proxy_handle_upstream` first polls, `select!` may read the 101 first. The queued pre-upgrade end of body is then handled after the upgrade, and `request_done && was_upgraded()` takes it for the end of the upgraded stream: the loop exits and both connections close right after the 101. A plain `Body` end handled after the upgrade now keeps receiving the upgraded body, as when it is handled before the 101. Only an `UpgradedBody` end or a dropped sender ends the upgraded stream. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015aL1hx3MokwQ9Zw5tvJcAb
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015aL1hx3MokwQ9Zw5tvJcAb
|
Same race as #947 (open since Aug 4) — good to see it described this cleanly. We have been running the fix from #947 in production since August (backported onto pingora 0.9.0), and the issue has picked up a few independent confirmations since. Two details from that PR that might be worth folding in here if maintainers want this one to be the landing:
Happy to close #947 in favor of this PR and port either of those over — either way, good to see this race getting a clean fix. |
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 race
For an HTTP/1.1 websocket upgrade (a
GETwithout a body),proxy_handle_downstreamqueuesHttpTask::Body(None, true)for the upstream half before the duplex loop starts. If the upstream's 101 is already readable whenproxy_handle_upstreamfirst polls,select!can read the 101 first. The queued pre-upgrade end of body is then handled after the upgrade, andrequest_done && client_session.was_upgraded()takes it for the end of the upgraded stream. The loop exits and both connections close right after the 101. When the end of body happens to be handled first, the existingrequest_done = falsereset on upgrade keeps the connection open, so the failure is intermittent.The fix
After the 101, the downstream half sends only
UpgradedBodytasks, so a plainBodyend handled after the upgrade can only be the request's own pre-upgrade end. In that caseproxy_handle_upstreamnow keeps receiving the upgraded body (request_done = false), the same as when that end is handled before the 101. AnUpgradedBodyend or a dropped sender still ends the upgraded stream.The test
proxy_h1::tests::upgraded_stream_survives_request_end_handled_after_101drivesproxy_handle_upstreamover atokio::io::duplexstream and forces the losing order: the peer writes the 101, the test waits for theHeadertask, and only then sendsBody(None, true)andUpgradedBody(Some("ping"), false). It asserts thatpingreaches the upstream and thatUpgradedBody(None, true)still ends the loop. Without the fix it fails, becausepingis never written. With the fix,cargo test -p pingora-proxy --libpasses (59 tests).Fixes #1050
🤖 Generated with Claude Code