From b5df084e1e0afbf6ec71f8fd4780a321987cfe9e Mon Sep 17 00:00:00 2001 From: atlowChemi Date: Thu, 6 Jul 2023 02:09:18 +0300 Subject: [PATCH] child_process: use addAbortListener PR-URL: https://github.com/nodejs/node/pull/48550 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Matteo Collina --- lib/child_process.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 59c37b97672d39..c32756437833b6 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -42,6 +42,7 @@ const { StringPrototypeIncludes, StringPrototypeSlice, StringPrototypeToUpperCase, + SymbolDispose, } = primordials; const { @@ -95,6 +96,7 @@ const { const MAX_BUFFER = 1024 * 1024; const isZOS = process.platform === 'os390'; +let addAbortListener; /** * Spawns a new Node.js process + fork. @@ -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() {