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>
  • Loading branch information
jakecastelli and ronag committed Jun 2, 2024
1 parent 954a6b3 commit c4e9405
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 = []

Check failure on line 90 in test/parallel/test-streams-highwatermark.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon
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'])

Check failure on line 109 in test/parallel/test-streams-highwatermark.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon
}))

Check failure on line 110 in test/parallel/test-streams-highwatermark.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon
}

0 comments on commit c4e9405

Please sign in to comment.