-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Missing "readable" event after some IO has occurred #5141
Comments
Aha!!! This is an interesting edge case. My point on the mailing list is that you don't have to do I consider this a bug, and I think it's easy to fix. |
@isaacs <3 thanks! FWIW I took a stab at this last night. I tried setting the |
In cases where a stream may have data added to the read queue before the user adds a 'readable' event, there is never any indication that it's time to start reading. True, there's already data there, which the user would get if they checked However, as we use 'readable' event listening as the signal to start the flow of data with a read(0) call internally, we ought to trigger the same effect (ie, emitting a 'readable' event) even if the 'readable' listener is added after the first emission. To avoid confusing weirdness, only the *first* 'readable' event listener is granted this privileged status. After we've started the flow (or, alerted the consumer that the flow has started) we don't need to start it again. At that point, it's the consumer's responsibility to consume the stream. Closes nodejs#5141
A stream should emit "readable" when it gets an EOF but has not yet passed its highWaterMark. Re: nodejs#5141
Thanks! I can confirm that the test cases you added to address this specific issue are passing. However, we're also missing readable events when a stream has not yet reached its |
Awesome, thanks for the failing test. I'll check that out and update the pull, probably tomorrow. |
@mjijackson Failing test fixed on 582c5b1. It's sufficiently different that it should be a separate commit, imo. Added to pull req. |
In cases where a stream may have data added to the read queue before the user adds a 'readable' event, there is never any indication that it's time to start reading. True, there's already data there, which the user would get if they checked However, as we use 'readable' event listening as the signal to start the flow of data with a read(0) call internally, we ought to trigger the same effect (ie, emitting a 'readable' event) even if the 'readable' listener is added after the first emission. To avoid confusing weirdness, only the *first* 'readable' event listener is granted this privileged status. After we've started the flow (or, alerted the consumer that the flow has started) we don't need to start it again. At that point, it's the consumer's responsibility to consume the stream. Closes #5141
Thanks @isaacs! Sorry for the slow response. |
This issue is a continuation of a discussion that we're having on the mailing list.
When I get a new
IncomingMessage
from anhttp.get
, and I wait for a bit, I consistently miss thereadable
event even though there are no other listeners already registered for that event. The following example illustrates the issue I'm seeing on node 0.10.1:As you can see from the example, I'm checking to make sure that there's nobody else listening for the
readable
event, so the stream shouldn't have already emitted it before I setup my handler inside the timeout. But I never get thereadable
event at all, or theend
event. Instead, the process just exits.The odd thing about this code is that I can sometimes get the
readable
event to fire if I use a very small timeout (like 1ms).The text was updated successfully, but these errors were encountered: