summaryrefslogtreecommitdiff
path: root/lib/child_process.js
diff options
context:
space:
mode:
authorBenjamin Gruenbaum <benjamingr@gmail.com>2020-12-07 12:54:50 +0200
committerBenjamin Gruenbaum <benjamingr@gmail.com>2020-12-22 17:53:00 +0200
commitf0a0e3c6b3fd55d7a7cadf310ef4a443c56082b9 (patch)
treeca0d82ab60fa3403d18a530f1afa11dd52d31e92 /lib/child_process.js
parent1623aff55c960e6e8d5c9fa534b7f49d4506a1b1 (diff)
downloadios-node-v8-f0a0e3c6b3fd55d7a7cadf310ef4a443c56082b9.tar.gz
ios-node-v8-f0a0e3c6b3fd55d7a7cadf310ef4a443c56082b9.tar.bz2
ios-node-v8-f0a0e3c6b3fd55d7a7cadf310ef4a443c56082b9.zip
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>
Diffstat (limited to 'lib/child_process.js')
-rw-r--r--lib/child_process.js9
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/child_process.js b/lib/child_process.js
index ae5a5f6587..29a6450210 100644
--- a/lib/child_process.js
+++ b/lib/child_process.js
@@ -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());
}
}