Skip to content

Commit ac11264

Browse files
atlowChemijuanarbol
authored andcommitted
net: use addAbortListener
PR-URL: #48550 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 002ce31 commit ac11264

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/net.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const {
3535
ObjectDefineProperty,
3636
ObjectSetPrototypeOf,
3737
Symbol,
38+
SymbolDispose,
3839
} = primordials;
3940

4041
const EventEmitter = require('events');
@@ -1605,17 +1606,18 @@ function afterConnect(status, handle, req, readable, writable) {
16051606
function addClientAbortSignalOption(self, options) {
16061607
validateAbortSignal(options.signal, 'options.signal');
16071608
const { signal } = options;
1609+
let disposable;
16081610

16091611
function onAbort() {
1610-
signal.removeEventListener('abort', onAbort);
1612+
disposable?.[SymbolDispose]();
16111613
self._aborted = true;
16121614
}
16131615

16141616
if (signal.aborted) {
16151617
process.nextTick(onAbort);
16161618
} else {
16171619
process.nextTick(() => {
1618-
signal.addEventListener('abort', onAbort);
1620+
disposable = EventEmitter.addAbortListener(signal, onAbort);
16191621
});
16201622
}
16211623
}
@@ -1695,8 +1697,8 @@ function addServerAbortSignalOption(self, options) {
16951697
if (signal.aborted) {
16961698
process.nextTick(onAborted);
16971699
} else {
1698-
signal.addEventListener('abort', onAborted);
1699-
self.once('close', () => signal.removeEventListener('abort', onAborted));
1700+
const disposable = EventEmitter.addAbortListener(signal, onAborted);
1701+
self.once('close', disposable[SymbolDispose]);
17001702
}
17011703
}
17021704

0 commit comments

Comments
 (0)