Repository navigation
proxy: preserve buffered data after protocol upgrade - #4435
Merged
MustafaSaber merged 3 commits intoNov 24, 2026
Merged
Conversation
Signed-off-by: Perfloop Agent <[email protected]> Signed-off-by: Tomás Senart <[email protected]>
Forward the backend response reader after a successful upgrade so data read ahead with the handshake reaches the client and the audit log. Signed-off-by: Perfloop Agent <[email protected]> Signed-off-by: Tomás Senart <[email protected]>
Limit the response reader to its buffered prefix so bulk forwarding keeps the raw connection copy path. Leave forwarding unchanged when the handshake did not read ahead. Signed-off-by: Perfloop Agent <[email protected]> Signed-off-by: Tomás Senart <[email protected]>
Member
|
@perfloop-agent can you create the PR to cwfreeze instead of master branch? |
Contributor
Author
|
@szuecs Done: the PR now targets The |
szuecs
approved these changes
Nov 16, 2026
MustafaSaber
approved these changes
Nov 24, 2026
szuecs
pushed a commit
that referenced
this pull request
Dec 1, 2026
An experimental WebSocket upgrade can return 101 while losing the start of a server-first frame sent with the handshake. This can drop a small frame completely or corrupt a larger frame, with either HTTP or HTTPS backends. Retain the backend response reader and drain its buffered bytes before copying the rest from the raw connection. Both direct and audited forwarding preserve byte order. When nothing was read ahead, the copy path is unchanged. Request-to-backend copying, non-101 response handling, and connection ownership remain unchanged. `TestUpgradeServerFirst` in `proxy/upgrade_test.go` sends a handshake and frame in one TLS record, with auditing off and on. It covers payload and buffer boundaries, a split-record control, subsequent bidirectional traffic, exact audit output, and backend-initiated EOF. The client-side `Hijack` reader is left unchanged: [RFC 6455 section 4.1](https://www.rfc-editor.org/rfc/rfc6455#section-4.1) requires clients to wait for the handshake response before sending more data, and `net/http/httputil.ReverseProxy` also copies from the hijacked connection. The focused Go tests for server-first forwarding, existing upgrade-response handling, and audit logging passed, including the race-enabled run. Formatting, vet, and staticcheck checks passed for the changed proxy code. The Redis-backed proxy tests `TestBackendRatelimitRoundRobin` and `TestBackendRatelimitScenarios` are left to target CI. This requires `ExperimentalUpgrade`; it does not enable the option. Fixes #4434. [Case and evidence](<https://app.perfloop.ai/t/oss/case_bbsc737fya>) --- Made by [Perfloop](https://app.perfloop.ai). Human sponsor: [Tomás Senart](https://github.com/tsenart). --------- Signed-off-by: Perfloop Agent <[email protected]> Signed-off-by: Tomás Senart <[email protected]> Signed-off-by: Sandor Szücs <[email protected]>
This was referenced Dec 2, 2026
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.
An experimental WebSocket upgrade can return 101 while losing the start of a server-first frame sent with the handshake. This can drop a small frame completely or corrupt a larger frame, with either HTTP or HTTPS backends.
Retain the backend response reader and drain its buffered bytes before copying the rest from the raw connection. Both direct and audited forwarding preserve byte order. When nothing was read ahead, the copy path is unchanged. Request-to-backend copying, non-101 response handling, and connection ownership remain unchanged.
TestUpgradeServerFirstinproxy/upgrade_test.gosends a handshake and frame in one TLS record, with auditing off and on. It covers payload and buffer boundaries, a split-record control, subsequent bidirectional traffic, exact audit output, and backend-initiated EOF.The client-side
Hijackreader is left unchanged: RFC 6455 section 4.1 requires clients to wait for the handshake response before sending more data, andnet/http/httputil.ReverseProxyalso copies from the hijacked connection.The focused Go tests for server-first forwarding, existing upgrade-response handling, and audit logging passed, including the race-enabled run. Formatting, vet, and staticcheck checks passed for the changed proxy code.
The Redis-backed proxy tests
TestBackendRatelimitRoundRobinandTestBackendRatelimitScenariosare left to target CI.This requires
ExperimentalUpgrade; it does not enable the option.Fixes #4434.
Case and evidence
Made by Perfloop. Human sponsor: Tomás Senart.