Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: prevent pipeline hang with generator functions #47712

Merged
merged 2 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
debadree25 marked this conversation as resolved.
Show resolved Hide resolved
await Promise.resolve();
yield 'world';
}, writable, { end: false }).then(common.mustCall(() => {
assert.strictEqual(res, 'helloworld');
assert.strictEqual(writable.closed, false);
}));
}