Repository navigation
Closed
Labels
streamIssues and PRs related to Node.js streams.
Description
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: endWith 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=trueIf 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=trueHow 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
Reacted by Jason Zhang and Dylan Landry
Metadata
Metadata
Assignees
Labels
streamIssues and PRs related to Node.js streams.
Activity
stream: prevent pipeline hang with generator functions
[-]pipeline with option end=false doesn't finish[/-][+]stream: pipeline with option end=false doesn't finish[/+]stream: prevent pipeline hang with generator functions
stream: prevent pipeline hang with generator functions
stream: prevent pipeline hang with generator functions
stream: prevent pipeline hang with generator functions
stream: prevent pipeline hang with generator functions