fix: destroy a connection attempt that no request waits for #6221
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 · 597 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
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.383
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #6221"
general
weight: 0.35
ronag
Stacked on #6219: it uses the abort path that #6219 adds to take a waiting request out of the Client queue. The base is
fix/abort-queued-requests. I'll retarget tomainonce #6219 lands.Problem
When every request waiting on a connecting Client is aborted, the connection attempt keeps going. It holds the Client, and with it a Pool connection slot, until it connects or hits
connectTimeout(10 s by default), and forever withconnectTimeout: 0. That is #386, "Client will connect even if all requests are aborted".#6219 makes it slightly worse in one case. The aborted request now leaves the Client queue, so the connecting Client is no longer busy and the Pool hands it the next request. That request then fails with the timeout of an attempt it did not start. On
mainit waited in the Pool queue and got a fresh connection after the timeout.Repro: a
connections: 1pool whose first connection hangs in the TLS handshake while later ones work. The only request is aborted at 100 ms, then a request without a signal is sent. "Pending" means not settled after 3 s.|
connectTimeout|main| #6219 | this PR ||---|---|---|---|
|
0| aborted: pending; next: pending | aborted: AbortError at once; next: pending | aborted: AbortError at once; next: 200 after 8 ms ||
2000| aborted: pending; next: 200 after 2.1 s | aborted: AbortError at once; next:UND_ERR_CONNECT_TIMEOUTafter 2.4 s | aborted: AbortError at once; next: 200 after 3 ms || default | aborted: pending; next: pending | aborted: AbortError at once; next: pending | aborted: AbortError at once; next: 200 after 3 ms |
A
request()to a host that never answers (10.255.255.1), aborted at 200 ms, now lets the process exit at 200 ms instead of 10.5 s.Changes
'drain'that the abort emits. A request queued in the Pool is handed to the Client in that drain and keeps the attempt alive. So does a request dispatched in the same tick as the abort.connectionError. Pool, RoundRobinPool and BalancedPool retire or penalize a client on'connectionError', so the cancellation does not emit it. It is published onundici:client:connectError, with anInformationalError, so diagnostics subscribers that sawbeforeConnectsee the attempt end.kConnectis never cancelled.Connector.mddocuments this, and the examples inConnector.mdandClient.mdnowreturn connector(...).Not covered
fetch()(#4405).fetch()does not pass the hook from #6219, so its aborted requests stay in the Client queue and the attempt is not cancelled. Same asmain: the process still waits for the connect timeout. Wiringfetch()to the hook would be a follow-up.client.destroy()while connecting. Unchanged: the socket is closed when the attempt calls back. #4412 covers it and could use the same handle.Tests
test/cancel-unused-connect.js, 10 tests:- h1 and h2 pools, with the default
connectTimeoutand with0;- a custom connector that returns its socket.
The hanging socket is closed, the next request succeeds on a new connection, and no
connectionErroris emitted.undici:client:connectError.- a request queued in the Pool;
- a second pipelined request;
- a request dispatched right after the abort;
- a connector that does not return its socket.
The waiting request is served on the original connection, and the server sees one connection.
Without the change, the five "destroyed" and "published" tests fail. If the check runs without waiting for the drain, the "queued in the Pool" and "dispatched right after the abort" tests fail.
Suites: unit 1724/1727, node-test 245/250, interceptors 513/516, cache-interceptor 87/87, h2 and fetch all pass. No failures; the rest are skipped. Lint is clean.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Sfj4nCVnJiJpsfbRdvDxpz