-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Don't inspect stream._readableState.ended #11
Comments
Custom streams are supported. A premature close event is only raised if |
It's not unusual for Eos is detecting different things for custom streams than it is for core class streams. For core streams, it's detecting if For custom (streams without the _typeState), it's detecting if the 'end' event or 'finish' event has happened, which is a much more restrictive check. |
Hey, I just had to add yet another one of these hacks to put off emitting
It's completely reasonable to read a file into a buffer, but not consume it yet. I can't emit I'm skeptical that "premature close" is even a thing to be worried about. What makes this so frustrating to me is that eos allows this exact semantic for built-in streams, but not for custom streams that lack a Would you be open to removing this check? Or perhaps make it opt-in? I'd be happy to send a PR with tests and documentation. |
There are many cases with node streams where Consider the following example var fs = require('fs')
var stream = fs.createReadStream('some-big-file')
stream.on('close', () => console.log('onclose'))
stream.on('end', () => console.log('onend'))
setTimeout(function () {
stream.destroy() // something destroys the stream
}, 1000) Here close is the only event fired and the only way to know the stream isn't fully buffered internally is to check the I'm happy to accept a PR that makes it easier to support non core streams though as long as we don't break things like above :) |
I 100% agree that the close semantics can be confusing to implement (why i always use 3rd party modules that hide all this) but that's how the core streams work, re error handling. |
I think the correct answer, then, would be to ignore "premature close" for any streams that aren't core streams, since there's no reliable way to know if the close is in fact premature. For core streams, with a Throwing an error in cases where there's nothing wrong is very disruptive. I get that you want to ensure, as much as possible, that the cb will fire in every case, but what's to stop a stream from not emitting close or end? For third-party streams, the cure is worse than the disease, and also not a cure. |
Nothing is stopping a stream from never emitting close or end no but that is the pragmatic part. All core streams emit close when destroyed and it is in the base classes as well. As long as we don't break support for popular modules like request I'm fine changing the behaviour for non core streams (pr welcome). I'm curious, how do you indicate a stream was destroyed in your stream impl? |
MiniPass doesn't have a |
Fix mafintosh#11 The timing of "close" events is implementation-specific. For core streams, it's reliably possible to determine if a close event is coming in advance of the stream actually being "done". However, if a stream doesn't have a _readableState or _writableState property, then it's impossible to determine if the close is "premature" or not.
Am I right in thinking commit isaacs/minipass@40e1d61 implements the proposed removal of |
@lovell Yeah, that broke a bunch of stuff that was already using Minipass streams have an |
Also, Minipass streams have |
The
onclose
handler is coupled to node core's stream implementation details, which creates some unfortunate problems for userland streams.If you have a readable stream that doesn't have a
_readableState
member (or writable/_writableState), then this always raises a premature close error.While it was straightforward to work around in my case, it was surprising and unnecessarily tricky to debug.
I suggest either of the following approaches:
The text was updated successfully, but these errors were encountered: