Skip to content

Apply connect timeout to the CONNECT request - #6

Merged
kelunik merged 1 commit into
amphp:2.xfrom
tomsommer:connect-timeout
Oct 25, 2026
Merged

kelunik merged 1 commit into
amphp:2.xfrom
tomsommer:connect-timeout

Conversation

@tomsommer

@tomsommer tomsommer commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

TunnelSocket::tunnel() creates the CONNECT request with new Request(...) and never sets a timeout, so opening the tunnel always uses the Request defaults of 10 seconds, whatever the caller configured.

DefaultConnectionFactory passes the request's TCP connect timeout to the connector via ConnectContext::withConnectTimeout(). That timeout is used for the TCP connection to the proxy, but not for the CONNECT request that follows. A proxy that is slow to reach the target (or never answers) therefore fails after 10 seconds even with a longer connect timeout, and can't be bounded by a shorter one either.

This passes the connect timeout from the ConnectContext through to the CONNECT request as its transfer and inactivity timeout, in both Http1TunnelConnector and Https1TunnelConnector. The CONNECT step gets the full connect timeout as its own window, the same way http-client applies the TCP connect and TLS handshake timeouts per step. Without a ConnectContext the timeout stays at 10 seconds, so the default behaviour is unchanged.

The added test points the connector at a socket that accepts but never responds, with a 0.5 second connect timeout. It hits the 2 second test limit before this change and passes in about 0.5 seconds after it.

Found via Symfony's AmpHttpClient, where proxied requests to unreachable hosts failed after 10 seconds instead of the configured timeout.

CI fails before the tests run: composer update can no longer resolve the leproxy/leproxy dev dependency, because Composer blocks the react/http 0.8 versions it needs over security advisories (PKSA-7xc4-r5ry-fg9s, PKSA-wsbn-q9bd-w7z2, PKSA-kwfb-dvpm-qtpb). That also affects 2.x and is unrelated to this change. Locally, with advisory blocking disabled, the full test suite and php-cs-fixer pass.

The CONNECT request was created with the Request defaults, so opening
the tunnel always timed out after 10 seconds, regardless of the connect
timeout in the ConnectContext. Use that timeout as the transfer and
inactivity timeout of the CONNECT request.
@kelunik
kelunik merged commit 40e1713 into amphp:2.x Oct 25, 2026
0 of 8 checks passed
@kelunik

kelunik commented Oct 25, 2026

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants