Skip to content

Commit b5df084

Browse files
atlowChemiruyadorno
authored andcommitted
child_process: use addAbortListener
PR-URL: #48550 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent f3c4300 commit b5df084

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

‎lib/child_process.js‎

Lines changed: 5 additions & 3 deletions
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
constMAX_BUFFER=1024*1024;
9697

9798
constisZOS=process.platform==='os390';
99+
letaddAbortListener;
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+
constdisposable=addAbortListener(signal,onAbortListener);
788+
child.once('exit',disposable[SymbolDispose]);
787789
}
788790

789791
functiononAbortListener(){

0 commit comments

Comments
(0)