Skip to content

Commit

Permalink
stream: prevent pipeline hang with generator functions
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
debadree25 authored and MoLow committed Jul 6, 2023
1 parent 8ca50b6 commit d3449ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/internal/streams/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,9 @@ async function pumpToNode(iterable, writable, finish, { end }) {

if (end) {
writable.end();
await wait();
}

await wait();

finish();
} catch (err) {
finish(error !== err ? aggregateTwoErrors(error, err) : err);
Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-stream-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -1616,3 +1616,21 @@ const tsp = require('timers/promises');
dup.push(null);
dup.read();
}

{
let res = '';
const writable = new Writable({
write(chunk, enc, cb) {
res += chunk;
cb();
}
});
pipelinep(async function*() {
yield 'hello';
await Promise.resolve();
yield 'world';
}, writable, { end: false }).then(common.mustCall(() => {
assert.strictEqual(res, 'helloworld');
assert.strictEqual(writable.closed, false);
}));
}

0 comments on commit d3449ca

Please sign in to comment.