Skip to content

Wait for CONNECT origin handshakes - #13512

Open
bneradt wants to merge 1 commit into
apache:masterfrom
bneradt:wait-for-connect-handshake
Open

Wait for CONNECT origin handshakes#13512
bneradt wants to merge 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.

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
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 on lines +33 to +37
def _configure_unavailable_origin(self) -> 'Process':
'''Reserve an origin port without starting a listening server.'''
origin = Test.MakeOriginServer('unavailable-origin')
self._origin = origin
return origin
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

2 participants