Skip to content

Commit

Permalink
child_process: use addAbortListener
Browse files Browse the repository at this point in the history
PR-URL: #48550
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
atlowChemi authored and ruyadorno committed Sep 16, 2023
1 parent f3c4300 commit b5df084
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/child_process.js
Expand Up @@ -42,6 +42,7 @@ const {
StringPrototypeIncludes,
StringPrototypeSlice,
StringPrototypeToUpperCase,
SymbolDispose,
} = primordials;

const {
Expand Down Expand Up @@ -95,6 +96,7 @@ const {
const MAX_BUFFER = 1024 * 1024;

const isZOS = process.platform === 'os390';
let addAbortListener;

/**
* Spawns a new Node.js process + fork.
Expand Down Expand Up @@ -781,9 +783,9 @@ function spawn(file, args, options) {
if (signal.aborted) {
process.nextTick(onAbortListener);
} else {
signal.addEventListener('abort', onAbortListener, { once: true });
child.once('exit',
() => signal.removeEventListener('abort', onAbortListener));
addAbortListener ??= require('events').addAbortListener;
const disposable = addAbortListener(signal, onAbortListener);
child.once('exit', disposable[SymbolDispose]);
}

function onAbortListener() {
Expand Down

0 comments on commit b5df084

Please sign in to comment.