Regression bug causing memory leak in AbortSignal.any() with long-lived parent signal.
The issue involves a regression bug in Node.js where AbortSignal.any() causes a memory leak when used with a long-lived parent signal. The bug was previously fixed but has resurfaced. The fix requires understanding the internals of AbortSignal and memory management.
v24.13.1, v25.8.1
Linux KContainer 5.10.0-12-amd64 #1 SMP Debian 5.10.103-1 (2022-03-07) x86_64 x86_64 x86_64 GNU/Linux
No response
Hi,
I would like to report a potential regression bug in Node. It can be reproduced by running the following snippet:
const ac = new AbortController();
let i = 0;
function run() {
// This is the operation that causes the leak: repeatedly creating
// a combined signal from the same long-lived parent signal.
AbortSignal.any([ac.signal]);
if (++i % 100_000 === 0) {
const mem = process.memoryUsage().rss / 1024 / 1024;
const kDependantSignals = Object.getOwnPropertySymbols(ac.signal).filter(
(s) => s.toString() === 'Symbol(kDependantSignals)'
)[0];
const signals = ac.signal[kDependantSignals];
console.log(`${i} - ${mem.toFixed(2)} MiB - ${signals?.size} signals`);
}
setImmediate(run);
}
run();
No specific condition
This issue was previously reported in #55351 and fixed in v22.12.0 'Jod' (https://github.com/nodejs/node/pull/55354)
root@KContainer:~/temp/55351# node -v
v22.12.0
root@KContainer:~/temp/55351# node test-any-leak.cjs
100000 - 84.80 MiB - 19191 signals
200000 - 95.71 MiB - 32634 signals
300000 - 98.24 MiB - 41438 signals
400000 - 95.88 MiB - 4510 signals
500000 - 96.83 MiB - 13195 signals
600000 - 97.34 MiB - 21910 signals
700000 - 97.34 MiB - 30580 signals
800000 - 98.64 MiB - 39250 signals
900000 - 96.63 MiB - 2309 signals
1000000 - 96.99 MiB - 11092 signals
1100000 - 97.77 MiB - 19777 signals
1200000 - 97.59 MiB - 28490 signals
1300000 - 99.08 MiB - 37238 signals
1400000 - 96.63 MiB - 329 signals
1500000 - 97.71 MiB - 9057 signals
1600000 - 98.16 MiB - 17778 signals
1700000 - 98.16 MiB - 26520 signals
1800000 - 99.60 MiB - 35267 si
Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!