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

Stop using stream.pipe() #1307

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

alxndrsn
Copy link
Contributor

@alxndrsn alxndrsn commented Nov 26, 2024

stream.pipe() should rarely be used in practice because:

  1. it can cause memory leaks, and
  2. it does not propogate errors between streams

PartialPipe.pipe() explicitly notes this and provides mitigations for it.

See:

@matthew-white

  • this would be a great candidate for a static check
  • this may help surface intermittent test failures more clearly

What has been done to verify that this works as intended?

Ran tests.

Why is this the best possible solution? Were any other approaches considered?

require('node:stream').pipeline(...) could be used in place of PartialPipe.pipeline() in some places. For instance:

PartialPipe.of(zipStream, outStream).pipeline(reject);

could be rewritten as:

pipeline([ zipStream, outStream ], reject);

The API is a bit different, so maybe it's helpful to be consistent.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

No effect.

Does this change require updates to the API documentation? If so, please update docs/api.yaml as part of this PR.

No.

Before submitting this PR, please make sure you have:

  • run make test and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code from external sources are properly credited in comments or that everything is internally sourced

alxndrsn added 2 commits November 26, 2024 08:26
stream.pipe() should rarely be used in practice because:

1. it can cause memory leaks, and
2. it does not propogate errors between streams

PartialPipe.pipeline() explicitly notes this and provides mitigations for it.

See:

* https://nodejs.org/api/stream.html#readablepipedestination-options
* https://stackoverflow.com/questions/58875655/whats-the-difference-between-pipe-and-pipeline-on-streams
@alxndrsn alxndrsn marked this pull request as ready for review November 27, 2024 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant