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

Deprecating autoDestroy: false and autoClose: false #30621

Closed
ronag opened this issue Nov 24, 2019 · 19 comments
Closed

Deprecating autoDestroy: false and autoClose: false #30621

ronag opened this issue Nov 24, 2019 · 19 comments
Labels
discuss Issues opened for discussions and feedbacks. stream Issues and PRs related to the stream subsystem.

Comments

@ronag
Copy link
Member

ronag commented Nov 24, 2019

I find allowing the option of not having autoDestroy and autoClose as problematic and I'm not sure what the motivation for these options would be for "correctly" implemented streams.

Would it be an option to change the defaults for these to true and documentation deprecating them? In order to make this transition faster we should explicitly set them to false in the places in core which are not yet updated for these.

From my experience when people try to use these options it's often due not fully understanding the streams API and trying to get around that but at the same time ending up accidentally creating some very subtle bugs.

@mcollina: Thoughts?

@lpinca
Copy link
Member

lpinca commented Nov 24, 2019

It is not always trivial to implement streams and these options help. For example I use autoDestroy and emitClose in ws https://github.com/websockets/ws/blob/7.2.0/lib/stream.js#L67-L68. Sometimes you need to change default behavior if it does not fit your needs.

I'm fine with changing defaults but not deprecating the options.

@lpinca lpinca added discuss Issues opened for discussions and feedbacks. stream Issues and PRs related to the stream subsystem. labels Nov 24, 2019
@mcollina
Copy link
Member

I’m -1 in deprecating, but + 1 in getting a semver-major PR that flip those defaults.

@ronag
Copy link
Member Author

ronag commented Nov 24, 2019

For example I use autoDestroy and emitClose in ws websockets/ws:lib/stream.js@7.2.0#L67-L68

I'm not convinced you need those options to implement that, e.g. https://gist.github.com/ronag/3fd8012fb0b0e23114714d1629c5a0a8. Probably doesn't work but just an example.

It's probably a bit to involved of an example for me to be able to argue my point without researching a some more into it.

@lpinca
Copy link
Member

lpinca commented Nov 24, 2019

I don't know, I don't currently have the time to think about all the edge cases solved in that implementation and verify that they also work as expected in your example, but another reason for which those options are used is that they allow me to make the stream work in the same way in all supported Node.js versions without using readable-stream.

@ronag
Copy link
Member Author

ronag commented Nov 24, 2019

The point here is not to re-write lots of existing code. My main point here is how to make future stream implementers not use the options unless strictly necessary (which should be very unusual).

I don't think just changing the defaults is enough to stop people from using these options as crutches. I guess an alternative to deprecation is to add explicit discouragement in the docs?

@mcollina
Copy link
Member

Let’s start with changing the defaults, I think deprecating might come 1 major after that, and we are already in Node 15 territory.

@lpinca
Copy link
Member

lpinca commented Nov 24, 2019

I don't think just changing the defaults is enough to stop people from using these options as crutches.

Maybe it's just me but I don't change defaults unless I have a good reason to do that so I don't think we should ever deprecate these options.

I mean, if I'm changing a default I know exactly what I'm doing and why I'm doing it but ofc I can't speak for other people.

@ronag
Copy link
Member Author

ronag commented Nov 24, 2019

I'm not convinced. I maintain that we should look into eventually deprecating them in the future. If I encounter any good example where they are indeed required I will of course reconsider. I don't think there is any hurry to actually remove them from the code. I'm mostly interested in the docs on this specific point.

@mcollina
Copy link
Member

I think you are contradicting yourself. On one side you say we won’t be able to port http2 to autoDestroy, and on the other that you’d like to deprecate or remove that option.

IMHO flipping the default is enough, and possibly doc-deprecation would be enough.

@ronag
Copy link
Member Author

ronag commented Nov 24, 2019

I think you are contradicting yourself. On one side you say we won’t be able to port http2 to autoDestroy, and on the other that you’d like to deprecate or remove that option.

I said it will be difficult and I don't think we can do it for 14.

I'm only arguing for doc-deprecation at this point, so I think we are in agreement.

Would it be an option to change the defaults for these to true and documentation deprecating them

@ronag ronag mentioned this issue Nov 24, 2019
6 tasks
BridgeAR pushed a commit that referenced this issue Jan 3, 2020
PR-URL: #30623
Refs: #30621
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
@davedoesdev
Copy link
Contributor

davedoesdev commented Jan 18, 2020

How do I check whether a stream was closed due explicit destroy() call or autoDestroy?

@ronag
Copy link
Member Author

ronag commented Jan 18, 2020

How do I check whether a stream was closed due explicit destroy() call or autoDestroy?

You can't. Why do you want this?

@davedoesdev
Copy link
Contributor

For testing, where I was assuming I'd get close or end but not both. It's fine, I'll share the same handler and only-once it.

@ronag
Copy link
Member Author

ronag commented Jan 18, 2020

I was assuming I'd get close or end but not both.

This is an incorrect assumption :). You should always get 'close'.

@davedoesdev
Copy link
Contributor

Only with #30623, right? I'm trying to get ahead of my tests failing.

@ronag
Copy link
Member Author

ronag commented Jan 18, 2020

Only with #30623, right? I'm trying to get ahead of my tests failing.

If you don't have autoDestroy: true you should call destroy()/destroy(err) yourself and thus 'close' should be emitted. But yea, if you don't do that then it won't be emitted, at all.

@ronag
Copy link
Member Author

ronag commented Feb 9, 2020

We've changed the default to true. I think this is mostly resolved through that.

@ronag ronag closed this as completed Feb 9, 2020
@kanongil
Copy link
Contributor

kanongil commented May 5, 2020

If you don't have autoDestroy: true you should call destroy()/destroy(err) yourself and thus 'close' should be emitted. But yea, if you don't do that then it won't be emitted, at all.

@ronag This is difficult to apply correctly to readables. If you call destroy() after push(null), it will immediately mark the stream destroyed, which means that anything that is still in the internal buffers can be discarded, depending on how the stream is consumed. To make it work, you have to listen to your own 'end' emit to time it.

@julienw
Copy link

julienw commented Jun 4, 2020

On one hand I'm mostly supportive of the change because it makes sense, on the other hand this small change produced a subtle bug in my code, probably because I was using the stream API incorrectly :-) I wonder if that should be made somewhat more visible in a "Changes that may break your code" section in the v14 changelog.
For example I like how the folks from Flow write their changelogs (see https://github.com/facebook/flow/releases/tag/v0.125.0 as an example).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss Issues opened for discussions and feedbacks. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

No branches or pull requests

6 participants