Skip to content

Commit d3449ca

Browse files
debadree25MoLow
authored andcommitted
stream: prevent pipeline hang with generator functions
Fixes: #47708 PR-URL: #47712 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Feng Yu <F3n67u@outlook.com>
1 parent 8ca50b6 commit d3449ca

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎lib/internal/streams/pipeline.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,9 @@ async function pumpToNode(iterable, writable, finish, { end }) {
138138

139139
if(end){
140140
writable.end();
141+
awaitwait();
141142
}
142143

143-
awaitwait();
144-
145144
finish();
146145
}catch(err){
147146
finish(error!==err ? aggregateTwoErrors(error,err) : err);

‎test/parallel/test-stream-pipeline.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,3 +1616,21 @@ const tsp = require('timers/promises');
16161616
dup.push(null);
16171617
dup.read();
16181618
}
1619+
1620+
{
1621+
letres='';
1622+
constwritable=newWritable({
1623+
write(chunk,enc,cb){
1624+
res+=chunk;
1625+
cb();
1626+
}
1627+
});
1628+
pipelinep(asyncfunction*(){
1629+
yield'hello';
1630+
awaitPromise.resolve();
1631+
yield'world';
1632+
},writable,{end: false}).then(common.mustCall(()=>{
1633+
assert.strictEqual(res,'helloworld');
1634+
assert.strictEqual(writable.closed,false);
1635+
}));
1636+
}

0 commit comments

Comments
 (0)