Repository navigation
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6223 +/- ##
==========================================
- Coverage 91.70% 91.69% -0.02%
==========================================
Files 113 113
Lines 44820 44874 +54
==========================================
+ Hits 41104 41146 +42
- Misses 3716 3728 +12 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mcollina
force-pushed
the
fix/cancel-abandoned-connect
branch
from
November 19, 2026 14:46
d85e2fe to
249dfc3
Compare
close() aborts the fetch of the EventSource. When its request was still in flight, the aborted network error then failed the connection and fired 'error', although readyState was already CLOSED. The spec only fires 'error' when failing a connection whose readyState is not CLOSED. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sfj4nCVnJiJpsfbRdvDxpz Signed-off-by: Matteo Collina <hello@matteocollina.com>
fetch() did not pass the queued-abort hook, so a fetch aborted while it waited for a connection stayed in the Pool or Client queue until a connection was ready. Its connection attempt kept running too: the process stayed alive until the connect timeout, and the pool slot stayed taken. A fetch that can be aborted now passes the hook. Until its request starts, aborting or terminating the fetch takes it out of the queue, and a connection attempt that no request waits for any more is destroyed. - fetch() passes the hook only when its Request follows a signal: without one, nothing can abort it before it starts, so it costs nothing. - fetching() passes it by default. WebSocket and EventSource abort their fetch on close(), and Cache.addAll() aborts the other fetches when one fails. - The hook chains with the abort of an attempt that already started, like the one for the other APIs, for interceptors such as retry. Fixes: #4405 Refs: #386 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sfj4nCVnJiJpsfbRdvDxpz Signed-off-by: Matteo Collina <hello@matteocollina.com>
mcollina
force-pushed
the
fix/fetch-abort-queued
branch
from
November 20, 2026 10:39
fcbc58e to
c9038d6
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #6219 and #6221, both landed. Rebased on
main.Fixes #4405.
Problem
fetch()does not pass the queued-abort hook that #6219 adds. A fetch aborted while it waits for a connection stays in the Pool or Client queue until a connection is ready, so #6221 never sees that nobody waits for the connection attempt any more. The repro in #4405, a fetch to a host that never answers aborted after a second, rejects at once but keeps the process alive until the 10 s connect timeout.WebSocket.close()andEventSource.close()while connecting leave the attempt running the same way.fetch()to a host that never answers, aborted at 200 msfetch()aborted in the Pool queueWebSocket.close()while the TLS handshake hangscloseat once; the handshake keeps runningcloseat once; the socket is closedEventSource.close()while the TLS handshake hangsChanges
fetch()passes the hook when it can be aborted. It does when its Request follows a signal. A Request without a signal has one that never aborts, so nothing can abort that fetch before it starts, and it gets no hook.fetching()passes it by default.WebSocketandEventSourceabort their fetch onclose(), andCache.addAll()aborts the other fetches when one fails.errorafterclose(). That is an existing bug onmain: closing while the request waits for response headers fireserrorwithreadyStatealreadyCLOSED. Onmain, a close while the TLS handshake hangs only reaches it after the connect timeout, and with this change it would happen at once, so it is fixed in its own commit. Per the spec, failing the connection fireserroronly "if the readyState attribute is set to a value other than CLOSED".Cost
Client CPU per
fetch(), median of 7 interleaved runs of 20,000 requests each, against #6221:Only a fetch that has a signal and waits in a queue pays for the hook, about 0.8 µs. Passing the hook to every fetch, which I measured first, cost +2.2% on queued fetches without a signal.
Tests
test/fetch/issue-4405.js, 8 tests:fetch()aborted while it waits:WebSocketandEventSourceclosed while the TLS handshake hangs: the attempt is destroyed, and EventSource fires noerror.test/eventsource/eventsource-close.jshas a new test: noerrorwhen closing before the response arrives.Without the
fetch()change, the hook, Pool-queue, TLS-hang, never-started-retry, WebSocket and EventSource tests fail. Without the EventSource fix, both EventSource tests fail.Suites: unit 1724/1727, fetch (with webidl and busboy) 607/607, websocket 178/178, eventsource 154/154, cache 5/5, node-test 245/250, interceptors 513/516, cache-interceptor 87/87. No failures; the rest are skipped. Lint is clean.
WPT
/eventsource,/websocketsand/fetch, run locally against the same WPT checkout on #6221 and on this branch: 3,865 passing and 2,944 failing on both, with the same status for every test. The failures are expected in my local setup; only the comparison matters here.🤖 Generated with Claude Code
https://claude.ai/code/session_01Sfj4nCVnJiJpsfbRdvDxpz