diff --git a/lib/api/api-request.js b/lib/api/api-request.js index e48925a4c84..d321db624c2 100644 --- a/lib/api/api-request.js +++ b/lib/api/api-request.js @@ -56,25 +56,20 @@ class RequestHandler extends AsyncResource { this.onInfo = onInfo || null this.throwOnError = throwOnError this.highWaterMark = highWaterMark - this.signal = signal this.reason = null this.removeAbortListener = null - if (this.signal?.aborted) { - this.reason = this.signal.reason ?? new RequestAbortedError() + if (signal?.aborted) { + this.reason = signal.reason ?? new RequestAbortedError() } else if (signal) { - this.removeAbortListener = util.addAbortListener(this.signal, () => { - this.reason = this.signal.reason ?? new RequestAbortedError() - } else { - this.removeAbortListener = util.addAbortListener(this.signal, () => { - this.reason = this.signal.reason ?? new RequestAbortedError() - if (this.res) { - util.destroy(this.res, this.reason) - } else if (this.abort) { - this.abort(this.reason) - } - }) - } + this.removeAbortListener = util.addAbortListener(signal, () => { + this.reason = signal.reason ?? new RequestAbortedError() + if (this.res) { + util.destroy(this.res, this.reason) + } else if (this.abort) { + this.abort(this.reason) + } + }) } }