Skip to content

Wait for CONNECT origin handshakes - #13512

Merged
bneradt merged 1 commit into
apache:masterfrom
bneradt:wait-for-connect-handshake
Aug 12, 2026
Merged

Wait for CONNECT origin handshakes#13512
bneradt merged 1 commit into
apache:masterfrom
bneradt:wait-for-connect-handshake

Conversation

@bneradt

@bneradt bneradt commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Explicit proxy CONNECT requests can return 200 before the
nonblocking origin connection finishes. A refused origin port then
looks like a successful tunnel followed by a client-side write failure.

This patch waits for write readiness on raw origin connections before
sending the CONNECT response. It reports connection failures to the
client and adds an AuTest covering a refused origin port.

Fixes: #7677

Verification

The new connect_handshake AuTest reserves an origin-server port but
deliberately does not start the server. A standalone Proxy Verifier client
then sends a CONNECT request through ATS and expects ATS to report the
refused origin connection with a 502.

Before this fix, the test reproduced the issue with:

[ERROR]: HTTP/1 Status Violation: expected 502 got 200, key: connect-refused : 29

After the fix, connect_handshake passes. The full connect* AuTest set
(7 tests) and tls_tunnel also pass in the asfats5 container.

Copilot AI lite review requested due to automatic review settings August 6, 2026 22:56
@bneradt bneradt added this to the 11.0.0 milestone Aug 6, 2026
@bneradt bneradt self-assigned this Aug 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an explicit proxy CONNECT edge case where ATS could respond 200 before the nonblocking origin TCP handshake completed, causing refused ports to appear as a successful tunnel followed by client-side write failures. The change makes ATS wait for origin write-readiness before confirming CONNECT success, and adds an AuTest to prevent regressions.

Changes:

  • Delay CONNECT success signaling until the raw origin connection reports write readiness (handshake complete).
  • Propagate raw origin connection failures (including timeouts / refused ports) back to the client as an error response.
  • Add a new Proxy Verifier replay + AuTest for “refused origin port” CONNECT behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/proxy/http/HttpSM.cc Wait for write readiness on raw origin connections before reporting CONNECT success; close/clean up properly on failures.
tests/gold_tests/connect/connect_handshake.test.py Adds an AuTest that exercises CONNECT to a deliberately-unavailable origin port and expects 502.
tests/gold_tests/connect/replays/connect_handshake.replay.yaml Proxy Verifier replay asserting ATS returns 502 for refused origin connections.

Comment thread tests/gold_tests/connect/connect_handshake.test.py Outdated
@bryancall
bryancall requested a review from serrislew August 10, 2026 22:25
Explicit proxy CONNECT requests can return 200 before the
nonblocking origin connection finishes. A refused origin port then
looks like a successful tunnel followed by a client-side write failure.

This patch waits for write readiness on raw origin connections before
sending the CONNECT response. It reports connection failures to the
client and adds an AuTest covering a refused origin port.

Fixes: apache#7677
@bneradt
bneradt force-pushed the wait-for-connect-handshake branch from b7e566b to 9620c09 Compare August 10, 2026 23:10
Copilot AI review requested due to automatic review settings August 10, 2026 23:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bneradt
bneradt merged commit b2d1b36 into apache:master Aug 12, 2026
15 checks passed
@bneradt
bneradt deleted the wait-for-connect-handshake branch August 12, 2026 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explicit proxy doesn't wait for TCP handshake to complete before sending 200 OK

3 participants