stream: prevent stream unexpected pause when highWaterMark set to 0

Co-authored-by: Robert Nagy <ronagy@icloud.com>
PR-URL: https://github.com/nodejs/node/pull/53261
Fixes: https://github.com/nodejs/node/issues/51930
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
jakecastelli 2024-06-08 11:34:40 +09:30 committed by GitHub
parent 5a446ccf37
commit 50695e5de1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View File

@ -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;

View File

@ -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']);
}));
}