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: add an option to let stream.pipeline not throw if the source is destroyed #48667

Open
ErickWendel opened this issue Jul 5, 2023 · 5 comments
Labels
feature request Issues that request new features to be added to Node.js. stale

Comments

@ErickWendel
Copy link
Member

ErickWendel commented Jul 5, 2023

What is the problem this feature will solve?

Reopening it to discuss.

When using standard source.pipe(dest) source will not be destroyed if dest emits close or an error.

stream.pipeline came to solve this problem but if the source is destroyed it throws an error of premature close.

see the example below:

import stream from 'stream'

setTimeout(() => process.stdin.destroy(), 200);

stream.promises.pipeline(
    process.stdin,
    process.stdout,
    { end: false }
)
// Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close

it works If I explicitly convert it to a readable stream and override it as:

import stream from 'stream'

const stdin = stream.Readable.from(process.stdin, { emitClose: false })
setTimeout(() => stdin.destroy(), 200);

stream.promises.pipeline(
    stdin,
    process.stdout,
    { end: false }
)

Still, for DX reasons pipeline IMHO should be able to consume partial streams without relying on its source if users want to.

cc @nodejs/streams WDYT?

What is the feature you are proposing to solve the problem?

The idea is to add an option to let stream.pipeline not throw if the source is destroyed. This is useful when working with files and an user disconnects from the webserver and it's not needed to consume the full stream

@nodejs/streams

What alternatives have you considered?

No response

@ErickWendel ErickWendel added the feature request Issues that request new features to be added to Node.js. label Jul 5, 2023
@ErickWendel
Copy link
Member Author

ErickWendel commented Jul 6, 2023

I updated the description with additional info

@ErickWendel ErickWendel reopened this Jul 6, 2023
Copy link
Contributor

github-actions bot commented Jan 3, 2024

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot added the stale label Jan 3, 2024
@mcollina
Copy link
Member

mcollina commented Jan 3, 2024

I'm sorry to have missed this issue.

Generically, I find this annoying in the promise version, as I often have to try/catch it to ignore that specific error.

@mcollina
Copy link
Member

mcollina commented Jan 3, 2024

Would you like to send a PR?

@github-actions github-actions bot removed the stale label Jan 4, 2024
Copy link
Contributor

github-actions bot commented Jul 2, 2024

There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the never-stale Mark issue so that it is never considered stale label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment.
For more information on how the project manages feature requests, please consult the feature request management document.

@github-actions github-actions bot added the stale label Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. stale
2 participants