Skip to content

Commit b8a1698

Browse files
committedJul 1, 2022
stream: fix Transform with hwm 0 regression
Fixes: nodejs#40935 Refs: nodejs#40947 Refs: nodejs#42457
1 parent 736a7d8 commit b8a1698

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed
 

‎lib/internal/streams/transform.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ Transform.prototype._write = function(chunk, encoding, callback) {
165165
wState.ended || // Backwards compat.
166166
length === rState.length || // Backwards compat.
167167
rState.length < rState.highWaterMark ||
168-
rState.highWaterMark === 0 ||
169168
rState.length === 0
170169
) {
171170
callback();
172171
} else {
173172
this[kCallback] = callback;
173+
rState.needReadable = true; // Always call _read() on the next read() call
174174
}
175175
});
176176
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const { Transform } = require('stream');
6+
7+
const t = new Transform({
8+
objectMode: true, highWaterMark: 0,
9+
transform(chunk, enc, callback) {
10+
process.nextTick(() => callback(null, chunk, enc));
11+
}
12+
});
13+
14+
assert.strictEqual(t.write(1), false);
15+
t.on('drain', common.mustCall(() => {
16+
assert.strictEqual(t.write(2), false);
17+
t.end();
18+
}));
19+
20+
t.once('readable', common.mustCall(() => {
21+
assert.strictEqual(t.read(), 1);
22+
setImmediate(common.mustCall(() => {
23+
assert.strictEqual(t.read(), null);
24+
t.once('readable', common.mustCall(() => {
25+
assert.strictEqual(t.read(), 2);
26+
}));
27+
}));
28+
}));

0 commit comments

Comments
 (0)
Please sign in to comment.