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 <ronagy@icloud.com>
PR-URL: nodejs#53261
Fixes: nodejs#51930
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
2 people authored and eliphazbouye committed Jun 20, 2024
1 parent 4cf6913 commit d7330ee
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 d7330ee

Please sign in to comment.