Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit dd5048e

Browse files
debadree25yjl9903
authored andcommittedApr 28, 2023
stream: prevent pipeline hang with generator functions
Fixes: nodejs#47708 PR-URL: nodejs#47712 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Feng Yu <[email protected]>
1 parent 18cb71b commit dd5048e

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed
 

‎lib/internal/streams/pipeline.js

+1-2
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+
await wait();
141142
}
142143

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

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

+18
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+
let res = '';
1622+
const writable = new Writable({
1623+
write(chunk, enc, cb) {
1624+
res += chunk;
1625+
cb();
1626+
}
1627+
});
1628+
pipelinep(async function*() {
1629+
yield 'hello';
1630+
await Promise.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)
Please sign in to comment.