fix: reject requests aborted while waiting for a connection #6219
All Vouch review confidence checks passed
Residual risk 0.26 = Change Risk (0.62) × (1 − Review Confidence (0.58)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.62 · 939 lines diff across 14 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.21 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
Bedrock Claude 3 · Risk Narration
(disconnected)
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.400
Shallow Review Depth
shallow_review_depth
0.278
Real PR Conversation Timeline
5 items
Codecov Report
:x: Patch coverage is
97.52066% with 6 lines in your changes missing coverage. Please review.:white_check_mark: Project coverage is 91.69%. Comparing base (
011d947) to head (7ea2aaa).| Files with missing lines | Patch % | Lines |
|---|---|---|
| lib/dispatcher/client.js | 86.66% | 6 Missing :warning: |
<details><summary>Additional details and impacted files</summary>
@@ Coverage Diff @@
## main #6219 +/- ##
==========================================
+ Coverage 91.67% 91.69% +0.01%
==========================================
Files 113 113
Lines 44489 44698 +209
==========================================
+ Hits 40786 40985 +199
- Misses 3703 3713 +10
</details>
:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.
<details><summary> :rocket: New features to boost your workflow: </summary>
</details>
Approved
Approved these changes.
Approved
Approved these changes.
Approved
Approved these changes.
ronag
mcollina
This relates to...
Fixes #386
Rationale
A request aborted while it waited for a connection only failed once it reached a socket. With a busy Pool, or a Client stuck connecting (for example a TLS handshake that never completes), the caller kept waiting long after the abort. #6117 handled a signal that is already aborted when
request()is called; this handles the rest.Changes
stats.queueddrops) and fails with the signal's reason.FixedQueuecan't remove from the middle, so the entry is marked dead and skipped when a connection frees up.close()resolves if it was the last queued request.'drain', so a Pool can use it again.request,stream,pipeline,connectandupgradepass a privatekQueuedAborthook todispatch(), only whensignalis set. While the request waits, the dispatcher calls the hook with a function that takes the request out of its queue; that function is the handler'sabortuntil the request starts. Requests without a signal take the same path as before.stream,pipeline,connectandupgradenow reject withsignal.reason, asrequestdoes, instead of a genericRequestAbortedError.stream(), an abort while a retry that resumes a partial body waited used to be lost, and the request completed successfully.request(), by signal or by destroying the body, no longer leaves the resume request queued to be sent later. This hook is only added once a retry happens.Features
N/A
Bug Fixes
A request aborted while queued in a Pool, or pending on a Client, fails immediately with the abort reason (#386).
Breaking Changes and Deprecations
None intended. Two visible differences:
stream,pipeline,connectandupgradereject withsignal.reason(notUND_ERR_ABORTED, unless that is the reason) and never connect.Interceptors
A request queued behind a busy connection rejects at once with the abort reason through
dump,decompress,responseError,retry,redirect,cache,deduplicate,dns, and all of them composed;test/issue-386.jscovers each. Unchanged frommain: withdeduplicate, a request that joined an identical one in flight only sees its own abort once the shared request starts, and aborting the first caller also fails the requests that joined it.Benchmark
Client CPU per request compared to
main(median over rotated runs; server in a separate process, one fresh client process per run):| scenario | change |
|---|---:|
| no signal, connections free | −0.1% |
| signal per request, connections free | +1.9% |
| no signal, requests queued | +0.6% |
| signal per request, requests queued | +1.1% |
| one shared signal, requests queued | +2.3% |
The no-signal results are within noise. I also tried having Client and Pool listen to the signal themselves: it cost about +4% without a signal and +11% to +19% with one, and it broke tests that count abort listeners.
Not covered here:
fetchdoes not pass its signal todispatch(). Its promise already rejects on abort, but the underlying request stays queued until it starts. That can be a follow-up.Status
<!-- KEY: S = Skipped, x = complete -->
[cert]: https://github.com/nodejs/undici/blob/main/CONTRIBUTING.md#developers-certificate-of-origin
🤖 Generated with Claude Code
https://claude.ai/code/session_01Sfj4nCVnJiJpsfbRdvDxpz