Skip to content

fix(http): honor HttpClient connect_timeout above 10s - #906

Merged
ithewei merged 1 commit into
masterfrom
fix/http-client-connect-timeout
Oct 12, 2026
Merged

ithewei merged 1 commit into
masterfrom
fix/http-client-connect-timeout

Conversation

@ithewei

@ithewei ithewei commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • http_client_connect capped the connect timeout at 10s: blocktime started at DEFAULT_CONNECT_TIMEOUT and was only ever lowered with MIN(), so req->connect_timeout (or the timeout argument of HttpClient::connect) above 10s had no effect. The same budget also covers the HTTP CONNECT tunnel and the TLS handshake.
  • Use connect_timeout as-is, falling back to the default only when it is unset, and cap it by the total timeout only when one is set. This also makes connect_timeout take effect when the total timeout is disabled on both the request and the client, which previously fell back to 10s.
  • AsyncHttpClient already uses connect_timeout directly and is unchanged.

Fixes #894

Verification

Connecting to 192.0.2.1:80 (RFC 5737 documentation range, unroutable) so the connect hangs until the timeout fires, on macOS:

connect_timeout total timeout before after
3s 60s 3.0s 3.0s
13s 60s 10.0s 13.0s
20s 60s 10.0s 20.0s
13s 0 (disabled) 10.0s 13.0s
13s 5s — 5.0s

Plain HTTP and HTTPS requests with the sync client, and HTTPS with the async client, still succeed against a local origin.

Note

The async client's total wait for an unreachable host includes its default retry (retry_count = 1, retry_delay = 1000ms), e.g. connect_timeout = 13 gives up after ~27s, while the sync client does not retry a failed connect. That difference is unchanged here.

http_client_connect started blocktime at DEFAULT_CONNECT_TIMEOUT (10s)
and only ever lowered it with MIN(), so a connect_timeout above 10s was
silently capped. The same budget also covers the HTTP CONNECT tunnel and
the TLS handshake.

Use connect_timeout as-is, falling back to the default only when it is
unset, and cap it by the total timeout only when one is set.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI balanced review requested due to automatic review settings October 12, 2026 12:34

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.

🟢 Approval recommended

The timeout calculation now matches the documented behavior without introducing unresolved issues.

0 open findings

What changed in this PR

Fixes synchronous HTTP connection timeouts above 10 seconds while preserving total-timeout limits.

Changes:

  • Uses the configured connection timeout directly.
  • Falls back to 10 seconds only when unset.
  • Caps connection time by the total timeout when enabled.
File Description
http/​client/​HttpClient.cpp Corrects synchronous connection timeout calculation.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ithewei
ithewei merged commit 881e9f2 into master Oct 12, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP 连接超时最大不能超过10s

2 participants