Skip to content

Commit 07b6bf4

Browse files
ronagruyadorno
authored andcommitted
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 PR-URL: #41848 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 5085813 commit 07b6bf4

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,19 @@ function readAndPause(){
5656
assert(readable.isPaused());
5757
});
5858
}
59+
60+
{
61+
const{ PassThrough }=require('stream');
62+
63+
constsource3=newPassThrough();
64+
consttarget3=newPassThrough();
65+
66+
constchunk=Buffer.allocUnsafe(1000);
67+
while(target3.write(chunk));
68+
69+
source3.pipe(target3);
70+
target3.on('drain',common.mustCall(()=>{
71+
assert(!source3.isPaused());
72+
}));
73+
target3.on('data',()=>{});
74+
}

0 commit comments

Comments
(0)