GeezerVison is showing github.com — stream: fix pipeline function tail deadlock · nodejs/node@9e889f4
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/stream/promises.js +11-1Lines changed: 11 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | const { |
| 4 | + ArrayIsArray, |
4 | 5 | ArrayPrototypePop, |
5 | 6 | Promise, |
6 | 7 | } = primordials; |
@@ -28,13 +29,22 @@ function pipeline(...streams) { |
28 | 29 | end = options.end; |
29 | 30 | } |
30 | 31 |
|
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) => { |
32 | 38 | if (err) { |
33 | 39 | reject(err); |
34 | 40 | } else { |
35 | 41 | resolve(value); |
36 | 42 | } |
37 | 43 | }, { signal, end }); |
| 44 | + |
| 45 | + if (typeof lastStream === 'function' && stream.readable) { |
| 46 | + stream.resume(); |
| 47 | + } |
38 | 48 | }); |
39 | 49 | } |
40 | 50 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-stream-pipeline.js +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1657,6 +1657,22 @@ tmpdir.refresh(); |
1657 | 1657 | })); |
1658 | 1658 | } |
1659 | 1659 |
|
| 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 | + |
1660 | 1676 | { |
1661 | 1677 | const r = new Readable(); |
1662 | 1678 | for (let i = 0; i < 4000; i++) { |
|