From a3092722fa215d3e3824452c4e1dbfb13c25a27b Mon Sep 17 00:00:00 2001 From: uzlopak Date: Mon, 26 Aug 2024 17:57:00 +0200 Subject: [PATCH] fix: avoid memoryleak in client-h1 --- lib/dispatcher/client-h1.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/dispatcher/client-h1.js b/lib/dispatcher/client-h1.js index 367b3c8d97d..fc7b962e06d 100644 --- a/lib/dispatcher/client-h1.js +++ b/lib/dispatcher/client-h1.js @@ -167,7 +167,7 @@ class Parser { if (value !== this.timeoutValue) { timers.clearTimeout(this.timeout) if (value) { - this.timeout = timers.setTimeout(onParserTimeout, value, this) + this.timeout = timers.setTimeout(onParserTimeout, value, new WeakRef(this)) // istanbul ignore else: only for jest if (this.timeout.unref) { this.timeout.unref() @@ -611,16 +611,16 @@ class Parser { } function onParserTimeout (parser) { - const { socket, timeoutType, client } = parser + const { socket, timeoutType, client, paused } = parser.deref() /* istanbul ignore else */ if (timeoutType === TIMEOUT_HEADERS) { if (!socket[kWriting] || socket.writableNeedDrain || client[kRunning] > 1) { - assert(!parser.paused, 'cannot be paused while waiting for headers') + assert(!paused, 'cannot be paused while waiting for headers') util.destroy(socket, new HeadersTimeoutError()) } } else if (timeoutType === TIMEOUT_BODY) { - if (!parser.paused) { + if (!paused) { util.destroy(socket, new BodyTimeoutError()) } } else if (timeoutType === TIMEOUT_IDLE) {