From a1574b03281589ce1d9853c84bf85bf7d496b709 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sat, 4 Feb 2023 13:20:59 +0100 Subject: [PATCH] fixup --- lib/client.js | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/client.js b/lib/client.js index 27de922e249..227132c734d 100644 --- a/lib/client.js +++ b/lib/client.js @@ -90,9 +90,9 @@ const fastNowInterval = setInterval(() => { // TODO (perf): This can probably be optimized. for (const timer of fastTimers) { - if (timer.expires && fastNow >= timer.expires) { - timer.expires = 0 - onParserTimeout.call(timer.self) + if (timer.timeoutExpires && fastNow >= timer.timeoutExpires) { + timer.timeoutExpires = 0 + onParserTimeout(timer) } } }, 1e3) @@ -440,8 +440,8 @@ class Parser { this.ptr = this.llhttp.llhttp_alloc(constants.TYPE.RESPONSE) this.client = client this.socket = socket - this.timeout = null - this.timeoutValue = null + this.timeoutExpires = 0 + this.timeoutValue = 0 this.timeoutType = null this.statusCode = null this.statusText = '' @@ -465,33 +465,32 @@ class Parser { this.timeoutType = type if (value === this.timeoutValue) { this.refreshTimeout() - } else { - this.timeoutValue = value - if (this.timeoutValue) { - if (!this.timeout) { - this.timeout = { - expires: fastNow + this.timeoutValue, - self: this - } - fastTimers.add(this.timeout) - } - this.timeout.expires = fastNow + this.timeoutValue - } else { - fastTimers.delete(this.timeout) + } else if (value) { + if (!this.timeoutValue) { + fastTimers.add(this) } + this.timeoutExpires = fastNow + value + } else { + fastTimers.delete(this) + this.timeoutExpires = 0 } + + this.timeoutValue = value } refreshTimeout () { - if (this.timeout) { - this.timeout.expires = fastNow + this.timeout.delay + if (this.timeoutValue) { + this.timeoutExpires = fastNow + this.timeoutValue } } clearTimeout () { - if (this.timeout) { - fastTimers.delete(this.timeout) + if (this.timeoutExpires) { + fastTimers.delete(this) } + + this.timeoutExpires = 0 + this.timeoutValue = 0 } resume () {