mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
child_process: clean event listener correctly
I was working on AbortSignal for spawn and noticed there is a leak in the current code for AbortSignal support in child_process since it removes the wrong listener. I used the new signal as argument feature to make removing the listener easier and added a test. PR-URL: https://github.com/nodejs/node/pull/36424 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
parent
1623aff55c
commit
f0a0e3c6b3
2 changed files with 16 additions and 6 deletions
|
@ -378,14 +378,13 @@ function execFile(file /* , args, options, callback */) {
|
|||
if (options.signal.aborted) {
|
||||
process.nextTick(() => kill());
|
||||
} else {
|
||||
const childController = new AbortController();
|
||||
options.signal.addEventListener('abort', () => {
|
||||
if (!ex) {
|
||||
if (!ex)
|
||||
ex = new AbortError();
|
||||
}
|
||||
kill();
|
||||
});
|
||||
const remove = () => options.signal.removeEventListener('abort', kill);
|
||||
child.once('close', remove);
|
||||
}, { signal: childController.signal });
|
||||
child.once('close', () => childController.abort());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue