Memory leak in AbortSignal.any() requires investigation of cleanup mechanisms.
The issue demonstrates a memory leak when using AbortSignal.any() in a loop, with memory not being properly released. The problem requires understanding of Node.js's AbortSignal implementation and memory management. Maintainers have noted potential duplicates and edge cases that complicate the fix.
v22.6.0
Microsoft Windows NT 10.0.22631.0 x64
Linux ****** 4.4.0-22621-Microsoft #3672-Microsoft Fri Jan 01 08:00:00 PST 2016 x86_64 x86_64 x86_64 GNU/Linux
https://nodejs.org/api/globals.html#class-abortsignal
Run this and watch memory usage.
const formatMemoryUsage = (data) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
let memoryData = process.memoryUsage();
console.log('Mem before loop', formatMemoryUsage(memoryData.rss));
for (let i = 0; true; i++) {
const abortController = new AbortController();
const signal = abortController.signal;
const composedSignal = AbortSignal.any([signal]);
if (i === 1000000) {
break;
}
}
memoryData = process.memoryUsage();
console.log('Mem after 1 million iteration', formatMemoryUsage(memoryData.rss));
This is what I get on my local machine
Always reproducible as far as I can tell
Memory post loop execution should be fairly equivalent to the first log but somehow the const composedSignal = AbortSignal.any([signal]); does not get cleaned up from memory, I would expect this to get cleaned properly or if this is the intended behavior to have a clear warning in the documentation.
We see a memory leak that will eventually lead to an out of memory error.
This has been tested on Node 22.6 on different machine and both Windows + Unix versions. Happy to provide more details if needed
Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!