Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: pipeline with option end=false doesn't finish #47708

Closed
xfournet opened this issue Apr 24, 2023 · 0 comments · Fixed by #47712
Closed

stream: pipeline with option end=false doesn't finish #47708

xfournet opened this issue Apr 24, 2023 · 0 comments · Fixed by #47712
Labels
stream Issues and PRs related to the stream subsystem.

Comments

@xfournet
Copy link

xfournet commented Apr 24, 2023

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

@F3n67u F3n67u added the stream Issues and PRs related to the stream subsystem. label Apr 25, 2023
debadree25 added a commit to debadree25/node that referenced this issue Apr 25, 2023
@xfournet xfournet changed the title pipeline with option end=false doesn't finish stream: pipeline with option end=false doesn't finish Apr 25, 2023
nodejs-github-bot pushed a commit that referenced this issue Apr 27, 2023
Fixes: #47708
PR-URL: #47712
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
yjl9903 pushed a commit to yjl9903/node that referenced this issue Apr 28, 2023
Fixes: nodejs#47708
PR-URL: nodejs#47712
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
yjl9903 pushed a commit to yjl9903/node that referenced this issue Apr 28, 2023
Fixes: nodejs#47708
PR-URL: nodejs#47712
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
yjl9903 pushed a commit to yjl9903/node that referenced this issue Apr 29, 2023
Fixes: nodejs#47708
PR-URL: nodejs#47712
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
targos pushed a commit that referenced this issue May 2, 2023
Fixes: #47708
PR-URL: #47712
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
targos pushed a commit that referenced this issue May 3, 2023
Fixes: #47708
PR-URL: #47712
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
danielleadams pushed a commit that referenced this issue Jul 6, 2023
Fixes: #47708
PR-URL: #47712
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
MoLow pushed a commit to MoLow/node that referenced this issue Jul 6, 2023
Fixes: nodejs#47708
PR-URL: nodejs#47712
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants