From ac11264cc56a5e9278dafde3d77d07cb0281378b Mon Sep 17 00:00:00 2001 From: atlowChemi Date: Thu, 6 Jul 2023 02:05:13 +0300 Subject: [PATCH] net: use addAbortListener PR-URL: https://github.com/nodejs/node/pull/48550 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Matteo Collina --- lib/net.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/net.js b/lib/net.js index 691f6bf57c7fd1..73d1343f3d8e09 100644 --- a/lib/net.js +++ b/lib/net.js @@ -35,6 +35,7 @@ const { ObjectDefineProperty, ObjectSetPrototypeOf, Symbol, + SymbolDispose, } = primordials; const EventEmitter = require('events'); @@ -1605,9 +1606,10 @@ function afterConnect(status, handle, req, readable, writable) { function addClientAbortSignalOption(self, options) { validateAbortSignal(options.signal, 'options.signal'); const { signal } = options; + let disposable; function onAbort() { - signal.removeEventListener('abort', onAbort); + disposable?.[SymbolDispose](); self._aborted = true; } @@ -1615,7 +1617,7 @@ function addClientAbortSignalOption(self, options) { process.nextTick(onAbort); } else { process.nextTick(() => { - signal.addEventListener('abort', onAbort); + disposable = EventEmitter.addAbortListener(signal, onAbort); }); } } @@ -1695,8 +1697,8 @@ function addServerAbortSignalOption(self, options) { if (signal.aborted) { process.nextTick(onAborted); } else { - signal.addEventListener('abort', onAborted); - self.once('close', () => signal.removeEventListener('abort', onAborted)); + const disposable = EventEmitter.addAbortListener(signal, onAborted); + self.once('close', disposable[SymbolDispose]); } }