Skip to content

Commit

Permalink
stream: fix memory usage regression in writable
Browse files Browse the repository at this point in the history
Setting writecb and afterWriteTickInfo to null did not clear the value
in the state object.

Amends 35ec931 (stream: writable state bitmap).

Fixes nodejs#52228.

PR-URL: nodejs#53188
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
  • Loading branch information
orgads authored and bmeck committed Jun 22, 2024
1 parent a0c440c commit 2445d8d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 2445d8d

Please sign in to comment.