Skip to content

Commit d73d83c

Browse files
atlowChemiCeres6
authored andcommitted
child_process: use addAbortListener
PR-URL: nodejs#48550 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 177ec8a commit d73d83c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/child_process.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const {
4242
StringPrototypeIncludes,
4343
StringPrototypeSlice,
4444
StringPrototypeToUpperCase,
45+
SymbolDispose,
4546
} = primordials;
4647

4748
const {
@@ -95,6 +96,7 @@ const {
9596
const MAX_BUFFER = 1024 * 1024;
9697

9798
const isZOS = process.platform === 'os390';
99+
let addAbortListener;
98100

99101
/**
100102
* Spawns a new Node.js process + fork.
@@ -781,9 +783,9 @@ function spawn(file, args, options) {
781783
if (signal.aborted) {
782784
process.nextTick(onAbortListener);
783785
} else {
784-
signal.addEventListener('abort', onAbortListener, { once: true });
785-
child.once('exit',
786-
() => signal.removeEventListener('abort', onAbortListener));
786+
addAbortListener ??= require('events').addAbortListener;
787+
const disposable = addAbortListener(signal, onAbortListener);
788+
child.once('exit', disposable[SymbolDispose]);
787789
}
788790

789791
function onAbortListener() {

0 commit comments

Comments
 (0)