1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(ext/node): ClientRequest.setTimeout(0) should remove listeners (#19240)

Co-authored-by: crowlkats <crowlkats@toaxl.com>
This commit is contained in:
Levente Kurusa 2023-05-24 22:54:12 +02:00 committed by GitHub
parent 91ca9904b5
commit 9ddb39d4cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;
}