Skip to content

Commit a2c5fcc

Browse files
committed
stream: resume stream on drain
Previously we would just resume "flowing" the stream without reseting the "paused" state. Fixes this by properly using pause/resume methods for .pipe. Fixes: #41785
1 parent 7faf763 commit a2c5fcc

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/internal/streams/readable.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,7 @@ function pipeOnDrain(src, dest) {
853853

854854
if ((!state.awaitDrainWriters || state.awaitDrainWriters.size === 0) &&
855855
EE.listenerCount(src, 'data')) {
856-
state.flowing = true;
857-
flow(src);
856+
src.resume();
858857
}
859858
};
860859
}

test/parallel/test-stream-readable-pause-and-resume.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,20 @@ function readAndPause() {
5656
assert(readable.isPaused());
5757
});
5858
}
59+
60+
{
61+
const { PassThrough } = require('stream');
62+
63+
const source3 = new PassThrough();
64+
const target3 = new PassThrough();
65+
66+
const chunk = Buffer.allocUnsafe(1000);
67+
let chunks = 1;
68+
while (target3.write(chunk)) chunks++;
69+
70+
source3.pipe(target3);
71+
target3.on('drain', common.mustCall(() => {
72+
assert(!source3.isPaused());
73+
}));
74+
target3.on('data', () => {});
75+
}

0 commit comments

Comments
 (0)