You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We noticed that AbortSignal.timeout() stopped working in our library with longer timeouts (in our case around 9s). Debugging showed that cloned (or constructor copied) requests won't respect an abort signal if GC has happened in between.
Reproducible By
Run with node --expose-gc
import{createServer}from'node:http';createServer(()=>{// server that just hangs}).listen(3000);constac=newAbortController();letreq=newRequest('http://localhost:3000',{signal: ac.signal,});// cloned or copied requests (req = new Request(req)) breaks abort after gcreq=req.clone();setTimeout(()=>{// comment out the gc to make abort workglobal.gc();ac.abort();console.log('aborted, expecting immediate exception from fetch...');});awaitfetch(req);
Commenting out the cloning and/or the gc will make the code work as expected, i.e. the fetch call rejecting after abort.
Expected Behavior
A cloned request should respect it's abort signal even after a long time (or garbage collection).
Debugging found that the difference before/after gc is that the "dependentControllerMap" entry for the signal is missing here
This looks familiar to another issue with fetch/signals caused by the AbortSignal implementation in node core but I couldn't find the issue. Should this be posted in node core instead? Is there anything we can do to fix this in undici?
@KhafraDev I haven't managed to reproduce without Request involved. Also holding on strongly to the original request doesn't help. To me it seems odd that this could be a pure AbortSignal problem? Ah, or maybe you're saying that there can be a bug in the internal api of AbortSignal (like dependentControllerMap), but undici is using the api correctly..
Still reproduces on Node v24.15.0 (bundled undici 7.24.4) and v24.12.0 (undici 7.16.0), with AbortSignal.timeout() as the parent signal. That is the pattern of SDKs that pass a cloned request to fetch with a timeout: after a collection, the timeout never reaches fetch, and the request waits forever.
Repro (node --expose-gc repro.mjs gc, or gc hold, or no argument):
constmode=process.argv[2]consthold=process.argv[3]==='hold'constheld=[]letcloneAborted=0letoriginalAborted=0for(leti=0;i<50;i++){consttimeout=AbortSignal.timeout(20)constoriginal=newRequest('https://example.test/',{signal: timeout})constclone=original.clone()if(hold)held.push(original,clone,timeout)awaitnewPromise((resolve)=>setImmediate(resolve))if(mode==='gc')globalThis.gc()constresult=awaitnewPromise((resolve)=>{constguard=setTimeout(()=>resolve('no abort'),200)clone.signal.addEventListener('abort',()=>{clearTimeout(guard);resolve('abort')},{once: true})})if(result==='abort')cloneAborted++if(original.signal.aborted)originalAborted++}console.log(`clone aborted ${cloneAborted}/50, original aborted ${originalAborted}/50`)
Results on v24.15.0, 50 runs each:
Mode
Clone signal aborted
Original signal aborted
Forced GC between clone() and the timeout
0/50
50/50
Forced GC, with both requests and the timeout signal held in variables
0/50
50/50
No forced GC
49/50
50/50
Holding the requests does not help, so the lost link is the clone's internal controller, not the request objects. In a test suite under load, a natural collection hit this in about 2 to 6 of 50 runs of a test that stubs fetch and waits for request.signal to abort.
The same sequence in workerd 1.20261001.1 aborts the clone 50/50.
Workaround for a test stub: wait on the parent signal (for example, spy on AbortSignal.timeout and wait on the signal it returned) instead of request.signal.
Activity
KhafraDev commentedon Feb 27, 2025
This looks familiar to another issue with fetch/signals caused by the AbortSignal implementation in node core but I couldn't find the issue. Should this be posted in node core instead? Is there anything we can do to fix this in undici?
andreas-karlsson commentedon Feb 28, 2025
@KhafraDev I haven't managed to reproduce without Request involved. Also holding on strongly to the original request doesn't help. To me it seems odd that this could be a pure AbortSignal problem? Ah, or maybe you're saying that there can be a bug in the internal api of AbortSignal (like dependentControllerMap), but undici is using the api correctly..
fix: ac lost on cloned request (nodejs#4068)
fix: ac lost on cloned request (nodejs#4068)
fix: ac lost on cloned request (nodejs#4068)
fix: ac lost on cloned request (nodejs#4068)
shiv19 commentedon Sep 27, 2026
still happening on Node 22.22, hit via @openrouter/sdk
rikbrown commentedon Oct 5, 2026
Still reproduces on Node v24.15.0 (bundled undici 7.24.4) and v24.12.0 (undici 7.16.0), with
AbortSignal.timeout()as the parent signal. That is the pattern of SDKs that pass a cloned request tofetchwith a timeout: after a collection, the timeout never reachesfetch, and the request waits forever.Repro (
node --expose-gc repro.mjs gc, orgc hold, or no argument):Results on v24.15.0, 50 runs each:
clone()and the timeoutHolding the requests does not help, so the lost link is the clone's internal controller, not the request objects. In a test suite under load, a natural collection hit this in about 2 to 6 of 50 runs of a test that stubs
fetchand waits forrequest.signalto abort.The same sequence in workerd 1.20261001.1 aborts the clone 50/50.
Workaround for a test stub: wait on the parent signal (for example, spy on
AbortSignal.timeoutand wait on the signal it returned) instead ofrequest.signal.fix(fetch): preserve abort propagation after garbage collection
fix(fetch): keep abort signal working after garbage collection
fix(fetch): preserve abort signals and request options (#10966)
fix(fetch): preserve abort signals and request options (#10966)
fix(fetch): preserve abort signals and request options (#10966)
fix: compose timeoutMs with caller signals and keep aborts working af…
fix(server): stop custom route agent runs on client disconnect after …
fix: keep tool deadlines and cancellation working after GC (#467)