Skip to content

Commit

Permalink
stream: prevent stream unexpected pause when highWaterMark set to 0
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Nagy <[email protected]>
PR-URL: nodejs#53261
Fixes: nodejs#51930
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
  • Loading branch information
jakecastelli and ronag authored Jun 8, 2024
1 parent 5a446cc commit 50695e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ function writeOrBuffer(stream, state, chunk, encoding, callback) {
state[kState] &= ~kSync;
}

const ret = state.length < state.highWaterMark;
const ret = state.length < state.highWaterMark || state.length === 0;

if (!ret) {
state[kState] |= kNeedDrain;
Expand Down
24 changes: 24 additions & 0 deletions test/parallel/test-streams-highwatermark.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,27 @@ const { inspect } = require('util');
hwm,
}));
}

{
const res = [];
const r = new stream.Readable({
read() {},
});
const w = new stream.Writable({
highWaterMark: 0,
write(chunk, encoding, callback) {
res.push(chunk.toString());
callback();
},
});

r.pipe(w);
r.push('a');
r.push('b');
r.push('c');
r.push(null);

r.on('end', common.mustCall(() => {
assert.deepStrictEqual(res, ['a', 'b', 'c']);
}));
}

0 comments on commit 50695e5

Please sign in to comment.