Skip to content

Commit

Permalink
fix(ext/node): ClientRequest.setTimeout(0) should remove listeners (#…
Browse files Browse the repository at this point in the history
…19240)

Co-authored-by: crowlkats <[email protected]>
  • Loading branch information
levex and crowlKats authored May 24, 2023
1 parent 91ca990 commit 9ddb39d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions ext/node/polyfills/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 9ddb39d

Please sign in to comment.