From c84d7d4330c7dd373e9b8a398a1a2d9cb6f6a953 Mon Sep 17 00:00:00 2001 From: Aras Abbasi Date: Tue, 27 Aug 2024 08:26:24 +0200 Subject: [PATCH] fix: avoid memoryleak in client-h1 (#3510) (cherry picked from commit b7254574e54d135d41baa5193f89007e78a3c710) --- 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 2f1c96724d3..1b0995a74c9 100644 --- a/lib/dispatcher/client-h1.js +++ b/lib/dispatcher/client-h1.js @@ -169,7 +169,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() @@ -613,16 +613,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) {