diff --git a/lib/api/api-request.js b/lib/api/api-request.js index ced5590d210..ca0343d606c 100644 --- a/lib/api/api-request.js +++ b/lib/api/api-request.js @@ -77,12 +77,6 @@ class RequestHandler extends AsyncResource { } else if (this.abort) { this.abort(this.reason) } - - if (this.removeAbortListener) { - this.res?.off('close', this.removeAbortListener) - this.removeAbortListener() - this.removeAbortListener = null - } }) } } @@ -127,6 +121,7 @@ class RequestHandler extends AsyncResource { if (this.removeAbortListener) { res.on('close', this.removeAbortListener) + this.removeAbortListener = null } this.callback = null @@ -183,7 +178,6 @@ class RequestHandler extends AsyncResource { } if (this.removeAbortListener) { - res?.off('close', this.removeAbortListener) this.removeAbortListener() this.removeAbortListener = null } diff --git a/lib/core/util.js b/lib/core/util.js index 00f8a9b200a..9b566ef2962 100644 --- a/lib/core/util.js +++ b/lib/core/util.js @@ -518,7 +518,7 @@ function addAbortListener (signal, listener) { signal.addEventListener('abort', listener, { once: true }) return () => signal.removeEventListener('abort', listener) } - signal.addListener('abort', listener) + signal.once('abort', listener) return () => signal.removeListener('abort', listener) }