← Back to Pull requests

fix(http): limit connection setup and enable TCP keepalive for HTTP clients #27247

Closed
unknown closed this pull request without merging on Nov 21, 2026 00:38 UTC
View on GitHub
unknown unknown commented on Nov 18, 2026 08:41 UTC
Author

Summary

HTTP client based sinks can leak sockets that are stuck in the TLS handshake, until the process runs out of file descriptors (#27245).

When a request needs a connection, hyper-util's legacy client races a pool checkout against a new connect. If the checkout wins after the connect has started, the unfinished connect is spawned into the background so that it can finish and be pooled. Nothing bounds that background task: the request timeout no longer applies to it, the connector has no connect timeout by default, and client sockets have no TCP keepalive. If the handshake stalls, for example because the peer's FIN/RST was lost on a lossy path, the socket stays open until Vector exits.

vector-http already supports ConnectionOptions::connect_timeout, which covers the TCP connect, the TLS handshake and a proxy CONNECT tunnel, but the HttpClient::new that sinks use did not set it. This PR:

  • Makes HttpClient::new (src/http/client.rs) limit connection setup to DEFAULT_CONNECT_TIMEOUT (65s). This is a little above the default sink request timeout (60s), so with default settings a connect made for a request is still ended by the request timeout first, as today. If both timers were 60s they could expire on the same tick and the request would fail with a connect error instead of Elapsed, which takes a different retry path. HttpClient::new_with_options is unchanged, so callers that pass their own options behave as before.

  • Enables TCP keepalive on outbound connections in vector-http's https_connector, with the curl CLI defaults: probes after 60s idle, every 60s, closing after 9 unanswered probes (about 600s to detect a dead peer). The kernel then closes a connection whose peer silently went away. This applies to every vector-http client.
  • User-visible changes:

  • Sinks built on HttpClient::new whose request.timeout_secs is above 65 now have a 65s limit on connection setup.

  • Idle outbound HTTP connections send keepalive probes after 60s, every 60s.
  • Not changed here, possible follow-ups:

  • The connect timeout and the keepalive settings are not configurable yet. As agreed in review, that is left for a follow-up.

  • Http2Client (the vector sink, the gcp_pubsub source) gets keepalive but no connect timeout. HTTP/2 connections are shared, so the background-connect race is much rarer there.

  • The AWS SDK client keeps following the SDK's own timeout settings.
  • References

    Closes: #27245

    Vector configuration

    The reproduction in #27245: a TLS server that answers the first connection and accepts but never answers the handshake of later ones, with ~170ms RTT added via netem, and an http sink with request.timeout_secs: 5.

    How did you test this PR?

  • cargo test -p vector-http --lib -- connector::tests: all pass.

  • - connect_timeout_bounds_a_stalled_tls_handshake now also checks that the client closes the stalled connection: after the ClientHello the server must read EOF within 5s. Before, it only checked that the request failed with TimedOut.
    - New client_connections_enable_tcp_keepalive checks SO_KEEPALIVE on a connection made by https_connector, and on Linux also the idle time, interval and probe count.
    - Mutation check: with set_keepalive or set_keepalive_interval removed, and with the connect spawned into a background task before the timeout (so the request fails but the socket stays open), the tests fail, at the keepalive assertions and at "the client should close the stalled connection". Removing set_keepalive_retries is not caught on Linux, because the kernel default is also 9.
  • New http::transport_tests::new_client_limits_a_stalled_connect_by_default: a client from HttpClient::new with no request timeout, against a server that never answers the handshake; after advancing the paused clock past DEFAULT_CONNECT_TIMEOUT, the request fails with TimedOut. With HttpClient::new reverted to ConnectionOptions::default(), the test fails. cargo test -p vector --lib --no-default-features -- http::: 66 passed.

  • End to end: we run the same approach (a 65s connect timeout around the connector plus keepalive with a 60s idle time) on a 0.44-based build. With the reproduction above, ESTABLISHED sockets grew linearly without the fix (1729 after 300s) and stayed flat at about 345 with it, with the same number of successful requests.

  • cargo clippy -p vector-http --all-targets -- -D warnings and cargo clippy -p vector --lib --tests --no-default-features -- -D warnings are clean, and rustfmt --check passes on the changed files. I did not run the full-feature make check-clippy locally (not enough memory on my machine).
  • Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.

  • No. A maintainer will apply the no-changelog label to this PR.
  • 🤖 Generated with Claude Code

    Diff: 625 lines (+468 / -157) across 7 files Reviewer: pront Review duration: 3836m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 625 lines diff across 7 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.385
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #27247"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.3% (MEDIUM) · Higher = larger blast radius
    50.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.9% · Safe to merge
    19.9%