Cloned requests loose abort signal on GC
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 880
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 68
Description
Bug Description
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);
const ac = new AbortController();
let req = new Request('http://localhost:3000', {
signal: ac.signal,
});
// cloned or copied requests (req = new Request(req)) breaks abort after gc
req = req.clone();
setTimeout(() => {
// comment out the gc to make abort work
global.gc();
ac.abort();
console.log('aborted, expecting immediate exception from fetch...');
});
await fetch(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).
Environment
macOS 15.3.1 (arm64), Node v23.4.0, v22.14.0, v20.18.0
Additional context
Debugging found that the difference before/after gc is that the "dependentControllerMap" entry for the signal is missing here
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in deps/undici/src/lib/web/fetch/request.js at the dependentControllerMap entry mentioned in the issue, then run the provided reproduction with node --expose-gc. Verify behavior with cloning, copying, and garbage collection; done means a cloned Request retains its abort behavior and fetch rejects promptly after ac.abort().
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100