diff options
author | Levente Kurusa <lkurusa@kernelstuff.org> | 2023-05-24 22:54:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-24 22:54:12 +0200 |
commit | 9ddb39d4cdde1985c7dc7beb38da3ce316c8e4dd (patch) | |
tree | dd36471c3fe3aad82f3ab914d05173f31f0d0983 | |
parent | 91ca9904b57db275a51a81ad71b1ee9fe42c7cda (diff) |
fix(ext/node): ClientRequest.setTimeout(0) should remove listeners (#19240)
Co-authored-by: crowlkats <crowlkats@toaxl.com>
-rw-r--r-- | ext/node/polyfills/http.ts | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index 1670ef0b9..93c802d37 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -349,7 +349,10 @@ class ClientRequest extends OutgoingMessage { this.socketPath = options!.socketPath; if (options!.timeout !== undefined) { - this.timeout = getTimerDuration(options.timeout, "timeout"); + const msecs = getTimerDuration(options.timeout, "timeout"); + const timeout = AbortSignal.timeout(msecs); + timeout.onabort = () => this.emit("timeout"); + this._timeout = timeout; } const signal = options!.signal; @@ -414,7 +417,6 @@ class ClientRequest extends OutgoingMessage { this._ended = false; this.res = null; this.aborted = false; - this.timeoutCb = null; this.upgradeOrConnect = false; this.parser = null; this.maxHeadersCount = null; @@ -803,6 +805,15 @@ class ClientRequest extends OutgoingMessage { } setTimeout(msecs: number, callback?: () => void) { + if (msecs === 0) { + if (this._timeout) { + this.removeAllListeners("timeout"); + this._timeout.onabort = () => {}; + this._timeout = undefined; + } + + return this; + } if (this._ended || this._timeout) { return this; } |