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 <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Feng Yu <[email protected]>
  • Loading branch information
debadree25 authored and targos committed May 3, 2023
1 parent d08dd80 commit f88132f
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 f88132f

Please sign in to comment.