镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

stream: add an option to let stream.pipeline not throw if the source is destroyed #48667

Description

@ErickWendel

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

Activity

  1. ErickWendel commented on Jul 6, 2023

    @ErickWendel
    MemberAuthor

    I updated the description with additional info

  2. github-actions commented on Jan 3, 2024

    @github-actions
    Contributor

    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.

  3. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jan 3, 2024
  4. mcollina commented on Jan 3, 2024

    @mcollina
    SponsorMember

    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.

  5. mcollina commented on Jan 3, 2024

    @mcollina
    SponsorMember

    Would you like to send a PR?

  6. removed
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jan 4, 2024
  7. github-actions commented on Jul 2, 2024

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the never-stale Issues and PRs exempt from automated stale handling. 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.

  8. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jul 2, 2024
  9. github-actions commented on Aug 1, 2024

    @github-actions
    Contributor

    There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions