Skip to content

Commit

Permalink
stream: resume stream on drain
Browse files Browse the repository at this point in the history
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

PR-URL: #41848
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
ronag authored and danielleadams committed Mar 8, 2022
1 parent 6fe708b commit 1dd1c79
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -830,8 +830,7 @@ function pipeOnDrain(src, dest) {

if ((!state.awaitDrainWriters || state.awaitDrainWriters.size === 0) &&
EE.listenerCount(src, 'data')) {
state.flowing = true;
flow(src);
src.resume();
}
};
}
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-stream-readable-pause-and-resume.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,19 @@ function readAndPause() {
assert(readable.isPaused());
});
}

{
const { PassThrough } = require('stream');

const source3 = new PassThrough();
const target3 = new PassThrough();

const chunk = Buffer.allocUnsafe(1000);
while (target3.write(chunk));

source3.pipe(target3);
target3.on('drain', common.mustCall(() => {
assert(!source3.isPaused());
}));
target3.on('data', () => {});
}

0 comments on commit 1dd1c79

Please sign in to comment.