Skip to content

Rely on stream.destroy() whenever available #4095

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

Merged
merged 3 commits into from
Mar 20, 2021

Conversation

kanongil
Copy link
Contributor

@kanongil kanongil commented Apr 26, 2020

Also updates a bunch of stream closing related test.

ReadableStream has included a .destroy() method since node 8. People can still provide older streams through old readable-stream module implementations.

Btw. non-destroyable streams should probably just error when returned from a handler, but that is a breaking change.

@kanongil
Copy link
Contributor Author

Anyone want to have a look at this?

Copy link
Member

@devinivy devinivy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. It's great to have these additional tests and to stay up to date with node. I don't detect any breaking changes since destroy() effectively constitutes a close() (e.g. including events that are subsequently emitted), and as far as I can tell should always take care of unpiping.

@kanongil
Copy link
Contributor Author

This looks good. It's great to have these additional tests and to stay up to date with node. I don't detect any breaking changes since destroy() effectively constitutes a close() (e.g. including events that are subsequently emitted), and as far as I can tell should always take care of unpiping.

Yeah, the stream integration is quite defensive, as streams were not that aligned during the earlier implementation. The story is much better now, and we can mostly just trust that client streams are somewhat well-behaved.

I'll see about re-basing this PR, and create a followup with a breaking change to deprecate any streams that don't include a destroy() method.

@kanongil
Copy link
Contributor Author

Incidentally, shot is one such broken client, as per #4149 & hapijs/shot#129 😬

@lloydbenson
Copy link
Contributor

As usual thanks for looking into this @kanongil. I am sure you probably noticed already but there is a conflict.

@kanongil
Copy link
Contributor Author

Rebased, and aliased the readable-stream require to clearly label it as a legacy module.

Copy link
Member

@Nargonath Nargonath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have an extensive knowledge about Streams but this LGTM. I also like the fact that we are following Node improvements.

There are also still some merge conflicts.

@devinivy devinivy added this to the 20.1.2 milestone Mar 20, 2021
@devinivy devinivy added feature New functionality or improvement test Test or coverage labels Mar 20, 2021
@devinivy devinivy merged commit 0e71bf4 into hapijs:master Mar 20, 2021
@devinivy devinivy self-assigned this Mar 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or improvement test Test or coverage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants