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 #52228.

PR-URL: #53188
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
  • Loading branch information
orgads authored and targos committed Jun 3, 2024
1 parent 07c601e commit a656cf6
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 a656cf6

Please sign in to comment.