Skip to content

Commit b725457

Browse files
authored
fix: avoid memoryleak in client-h1 (#3510)
1 parent 1e91a3e commit b725457

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

lib/dispatcher/client-h1.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class Parser {
167167
if (value !== this.timeoutValue) {
168168
timers.clearTimeout(this.timeout)
169169
if (value) {
170-
this.timeout = timers.setTimeout(onParserTimeout, value, this)
170+
this.timeout = timers.setTimeout(onParserTimeout, value, new WeakRef(this))
171171
// istanbul ignore else: only for jest
172172
if (this.timeout.unref) {
173173
this.timeout.unref()
@@ -611,16 +611,16 @@ class Parser {
611611
}
612612

613613
function onParserTimeout (parser) {
614-
const { socket, timeoutType, client } = parser
614+
const { socket, timeoutType, client, paused } = parser.deref()
615615

616616
/* istanbul ignore else */
617617
if (timeoutType === TIMEOUT_HEADERS) {
618618
if (!socket[kWriting] || socket.writableNeedDrain || client[kRunning] > 1) {
619-
assert(!parser.paused, 'cannot be paused while waiting for headers')
619+
assert(!paused, 'cannot be paused while waiting for headers')
620620
util.destroy(socket, new HeadersTimeoutError())
621621
}
622622
} else if (timeoutType === TIMEOUT_BODY) {
623-
if (!parser.paused) {
623+
if (!paused) {
624624
util.destroy(socket, new BodyTimeoutError())
625625
}
626626
} else if (timeoutType === TIMEOUT_IDLE) {

0 commit comments

Comments
 (0)