stream: pipeline with option end=false doesn't finish
Version
Reproduced on 19.9.0 and 20.0.0
Platform
Microsoft Windows NT 10.0.22621.0 x64
Subsystem
No response
What steps will reproduce the bug?
Put this code into a testPipeline.mjs file
import { Readable, Writable } from 'stream'; import { pipeline } from 'stream/promises'; const useReadableFrom = process.argv.includes('-r'); const end = process.argv.includes('-e'); console.log({ useReadableFrom, end }); export async function* gen() { console.log('generator: start'); yield 'test1'; console.log('generator: end'); } const destination = new Writable({ write: (chunk, encoding, callback) => callback() }); console.log('pipeline: start'); await pipeline( useReadableFrom ? Readable.from(gen()) : gen(), destination, { end }, ); console.log(`pipeline: end, destination.closed=${destination.closed}`);
With no options, the script terminate without printing the last log, this is the issue.
❯ node testPipeline.mjs { useReadableFrom: false, end: false } pipeline: start generator: start generator: end
With the end option (default behavior of pipeline), the script correctly executes:
❯ node testPipeline.mjs -e { useReadableFrom: false, end: true } pipeline: start generator: start generator: end pipeline: end, destination.closed=true
If the generator is encapsulated into a Readable, it works whatever the end option:
❯ node testPipeline.mjs -r { useReadableFrom: true, end: false } pipeline: start generator: start generator: end pipeline: end, destination.closed=false
❯ node testPipeline.mjs -r -e { useReadableFrom: true, end: true } pipeline: start generator: start generator: end pipeline: end, destination.closed=true
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
The expected behavior is the program to continue after the pipeline terminate
What do you see instead?
Program stops before executing the next line after the pipeline
Additional information
No response