From 850a60fb74f788f6fd4b2c3f3014d0a9c5ec24d4 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sat, 22 Jun 2024 21:40:10 +0200 Subject: [PATCH] refactor: simplify signal handling --- lib/api/api-request.js | 8 +------- lib/core/util.js | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) 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) }