← Back to Pull requests

fix(pool): fail requests queued behind a failed protocol probe together #6241

Open
unknown opened this pull request with 494 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 21, 2026 07:01 UTC
Author

This relates to...

Fixes https://github.com/nodejs/undici/issues/6238

Rationale

This is a regression introduced in 8.11.0 by #5799 ("avoid pool fan-out during ALPN
negotiation"). Requests to an HTTPS origin are held in the pool queue behind a single
"protocol probe" client until ALPN reveals whether the origin speaks h1 or h2.

If that probe's connection attempt fails, the pool retires it and hands the next queued
request to a new probe client. Each new client starts its connectTimeout when it is
created, so the time already spent waiting in the queue is not counted anywhere. The
result is that a backlog of N requests against an origin that accepts TCP but never
answers the TLS handshake rejects one connect timeout after another, the n-th only after
roughly n connect timeouts.

Measured with connectTimeout = 2000ms and four concurrent fetch() calls through one
Agent, against a local net server that accepts the connection and never answers the TLS
handshake:

before (undici 8.13.1):

2.5s, 5.1s, 7.6s, 10.1s

after this patch:

about 2.6s for each of the four requests

undici 8.5.0 rejected all four together, so this restores the pre-#5799 behavior for the
failed-probe case.

Changes

Bug Fixes

lib/dispatcher/pool-base.js: add [kFailQueue](err), which settles every request still
waiting in the pool queue with one already-observed error. It reuses kShiftQueue, so
aborted tombstones are skipped exactly as in kDrainQueue, and it mirrors how
kDestroy/kAbortQueued settle queued work. It only settles the backlog that existed when
it was called, so a handler that synchronously dispatches a new request does not
inherit the error.

lib/dispatcher/pool.js: the connectionError handler now receives the connection error.
When the failed target is the protocol probe, the backlog is settled with that error
instead of being re-probed one request at a time.

The new path is deliberately narrow. It only runs when the failed client is the protocol
probe. While the probe gate is up, kGetDispatcher() returns no dispatcher for any other
request, so the queue can only be waiting on that probe. Pools that already established a
protocol, and connection errors on non-probe clients, keep the existing drain-and-retry
behavior.

Breaking Changes and Deprecations

N/A

Status

  • I have read and agreed to the Developer's Certificate of Origin

  • Tested

  • Benchmarked (optional)

  • Documented

  • Review ready
  • Notes for reviewers

    test/issue-6238.js starts a net server that accepts the TCP connection and never answers
    the TLS handshake, then asserts that four concurrent fetch() calls through one Agent all
    reject with UND_ERR_CONNECT_TIMEOUT within 2 * connectTimeout.

    The alternative shape is to count time spent queued behind the probe towards each
    request's connect budget, for example by stamping the enqueue time on QueuedRequest and
    checking a deadline in kDrainQueue. That keeps the retry, but it is a larger change and it
    needs a decision on whether queue wait should consume a request's connect budget at all.
    I went with settling the backlog because every queued request would otherwise retry the
    same origin that the probe has just failed to reach, and because the observable result
    matches the expectation in the issue. Happy to switch to the per-request deadline shape
    if you prefer it.

    One trade-off worth stating explicitly: with this patch a transient connect failure fails
    the queued batch instead of retrying it on a fresh connection. Requests that arrive after
    the probe failed still create a new probe and are retried normally. undici has no default
    request-level retry (RetryHandler is a separate, opt-in interceptor), and the current
    serial behavior turns an O(1) failure into O(n) connect timeouts, so failing together
    seems like the better default here. If you would rather keep the retry, the per-request
    deadline shape above is the way to go.

    Diff: 494 lines (+370 / -124) across 6 files Reviewer: mcollina Review duration: 2258m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.47) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 494 lines diff across 6 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.371
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #6241"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 47.4% (MEDIUM) · Higher = larger blast radius
    47.4%
    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: 46.7% · Lower = rushed or shallow review
    46.7%
    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: 25.3% · Safe to merge
    25.3%
    Repository