Skip to content

Commit dcc8665

Browse files
dayun6530aduh95
authored andcommitted
stream: fix pipeline function tail deadlock
Signed-off-by: Dayun <dlekdbs6530@gmail.com> PR-URL: #65559 Fixes: #40685 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 19732fc commit dcc8665

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎lib/stream/promises.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const {
4+
ArrayIsArray,
45
ArrayPrototypePop,
56
Promise,
67
} = primordials;
@@ -28,13 +29,22 @@ function pipeline(...streams) {
2829
end = options.end;
2930
}
3031

31-
pl(streams, (err, value) => {
32+
let lastStream = streams[streams.length - 1];
33+
if (streams.length === 1 && ArrayIsArray(streams[0])) {
34+
lastStream = streams[0][streams[0].length - 1];
35+
}
36+
37+
const stream = pl(streams, (err, value) => {
3238
if (err) {
3339
reject(err);
3440
} else {
3541
resolve(value);
3642
}
3743
}, { signal, end });
44+
45+
if (typeof lastStream === 'function' && stream.readable) {
46+
stream.resume();
47+
}
3848
});
3949
}
4050

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,22 @@ tmpdir.refresh();
16571657
}));
16581658
}
16591659

1660+
{
1661+
async function* passThrough(source) {
1662+
for await (const chunk of source) {
1663+
yield chunk;
1664+
}
1665+
}
1666+
1667+
const streams = () => [
1668+
Readable.from(Array.from({ length: 100 }, (_, i) => i)),
1669+
passThrough,
1670+
];
1671+
1672+
pipelinep(...streams()).then(common.mustCall());
1673+
pipelinep(streams()).then(common.mustCall());
1674+
}
1675+
16601676
{
16611677
const r = new Readable();
16621678
for (let i = 0; i < 4000; i++) {

0 commit comments

Comments
 (0)