Repository navigation
client: HttpClientBuilder with connect_timeout - #117
Merged
Merged
Conversation
HttpClient::plaintext()/plaintext_http2_only()/with_tls() each construct an HttpConnector inline with no way to set connect_timeout. That leaves the TCP connect phase bounded only by kernel tcp_syn_retries (~130s on Linux defaults). Callers on paths that can silently drop SYNs (e.g. NAT gateways under churn) have no way to fail fast short of a per-request timeout that conflates connect with the request body. This adds HttpClientBuilder, obtained via HttpClient::builder(), with a connect_timeout(Duration) setter that flows through to HttpConnector::set_connect_timeout for all three transport flavours. The existing constructors delegate to the builder with no timeout set, preserving behaviour. Http2Connection/MakeSendRequest are left untouched for now — follow-up if there is demand. The setter bounds only the TCP connect(2) call (per resolved address; hyper divides the budget across the address set). DNS resolution and the TLS handshake are not covered; the doc comment points callers at CallOptions::with_timeout for an end-to-end bound.
|
All contributors have signed the CLA ✍️ ✅ |
Collaborator
Author
|
I have read the CLA Document and I hereby sign the CLA |
iainmcgin
approved these changes
May 19, 2026
azdagron
enabled auto-merge (squash)
May 19, 2026 16:22
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Motivation
HttpClient::plaintext()/plaintext_http2_only()/with_tls()each construct anHttpConnectorinline with no way to setconnect_timeout. The TCP connect phase is therefore bounded only by the kernel'stcp_syn_retries(~130s on Linux defaults). Callers on network paths that can silently drop SYNs — NAT gateways under churn are the motivating case — have no way to fail fast short of a per-request timeout, which conflates the connect phase with TLS handshake and request body.What
Adds
HttpClientBuilder, obtained viaHttpClient::builder(), with aconnect_timeout(Duration)setter that flows through toHttpConnector::set_connect_timeoutfor all three transport flavours. The three existing associated constructors now delegate to the builder with no timeout set, so behaviour is unchanged for existing callers and the connector setup lives in one place.The setter bounds only the TCP
connect(2)call (per resolved address — hyper divides the budget across the address set). It does not cover DNS resolution or, forwith_tls, the TLS handshake. The doc comment points callers atCallOptions::with_timeoutfor an end-to-end bound;connect_timeoutis for the case where you want to retry connect quickly without aborting an in-flight request body.Not in this PR
Http2Connection/MakeSendRequestinclient/http2.rsbuild their ownHttpConnectorinstances and are left untouched. Happy to follow up with the same builder shape there if there's demand; the immediate consumer usesHttpClient.Testing
http_client_connect_timeout_bounds_tcp_connectsends to a TEST-NET-1 address (RFC 5737, guaranteed unroutable) with a 100 ms connect timeout and asserts the failure surfaces within 2 s — well under the kernel SYN-retry floor an unbounded connect would hit. Existing 324 lib tests pass unchanged.