Skip to content

Commit 914d25e

Browse files
jakecastellironag
andcommitted
stream: prevent stream unexpected pause when highWaterMark set to 0
Co-authored-by: Robert Nagy <ronagy@icloud.com>
1 parent 954a6b3 commit 914d25e

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/internal/streams/writable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ function writeOrBuffer(stream, state, chunk, encoding, callback) {
565565
state[kState] &= ~kSync;
566566
}
567567

568-
const ret = state.length < state.highWaterMark;
568+
const ret = state.length < state.highWaterMark || state.length === 0;
569569

570570
if (!ret) {
571571
state[kState] |= kNeedDrain;

test/parallel/test-streams-highwatermark.js

+24
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,27 @@ const { inspect } = require('util');
8585
hwm,
8686
}));
8787
}
88+
89+
{
90+
const res = [];
91+
const r = new stream.Readable({
92+
read() {},
93+
});
94+
const w = new stream.Writable({
95+
highWaterMark: 0,
96+
write(chunk, encoding, callback) {
97+
res.push(chunk.toString());
98+
callback();
99+
},
100+
});
101+
102+
r.pipe(w);
103+
r.push('a');
104+
r.push('b');
105+
r.push('c');
106+
r.push(null);
107+
108+
r.on('end', common.mustCall(() => {
109+
assert.deepStrictEqual(res, ['a', 'b', 'c']);
110+
}));
111+
}

0 commit comments

Comments
 (0)