From a656cf6bc802998e069429f2dd5ed56083f0d693 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Sun, 2 Jun 2024 03:35:36 +0300 Subject: [PATCH] stream: fix memory usage regression in writable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Setting writecb and afterWriteTickInfo to null did not clear the value in the state object. Amends 35ec93115d (stream: writable state bitmap). Fixes #52228. PR-URL: https://github.com/nodejs/node/pull/53188 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Matteo Collina Reviewed-By: Luigi Pinca Reviewed-By: Vinícius Lourenço Claro Cardoso --- lib/internal/streams/writable.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/internal/streams/writable.js b/lib/internal/streams/writable.js index a039e60b16c2c2..38f1cbadd39d1d 100644 --- a/lib/internal/streams/writable.js +++ b/lib/internal/streams/writable.js @@ -252,8 +252,8 @@ ObjectDefineProperties(WritableState.prototype, { enumerable: false, get() { return (this[kState] & kWriteCb) !== 0 ? this[kWriteCbValue] : nop; }, set(value) { + this[kWriteCbValue] = value; if (value) { - this[kWriteCbValue] = value; this[kState] |= kWriteCb; } else { this[kState] &= ~kWriteCb; @@ -268,8 +268,8 @@ ObjectDefineProperties(WritableState.prototype, { enumerable: false, get() { return (this[kState] & kAfterWriteTickInfo) !== 0 ? this[kAfterWriteTickInfoValue] : null; }, set(value) { + this[kAfterWriteTickInfoValue] = value; if (value) { - this[kAfterWriteTickInfoValue] = value; this[kState] |= kAfterWriteTickInfo; } else { this[kState] &= ~kAfterWriteTickInfo; @@ -615,7 +615,8 @@ function onwrite(stream, er) { const sync = (state[kState] & kSync) !== 0; const cb = (state[kState] & kWriteCb) !== 0 ? state[kWriteCbValue] : nop; - state[kState] &= ~(kWriting | kExpectWriteCb | kWriteCb); + state.writecb = null; + state[kState] &= ~(kWriting | kExpectWriteCb); state.length -= state.writelen; state.writelen = 0;