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
fix needDrain emitting to match the amount of pauses #4
Conversation
what is currently happening? the way you phrased it it sounds like it's emitting too many pauses not not enough drains. it should not emit another pause unless it's emitted drain since the last pause. As a regular expression: |
I was able to simulate the problem I had in my code with a test, that I just added, the change fixes that. I hope that code explains better what issue I am trying to solve. |
it would help if you describe the problem? it's harder to interpret code than text |
Of course. Given a src readable stream and a dest writable stream, which are
The above behaviour results in what you mentioned of pausing multiple times one after another, without With the current code where I put the The best solution I could come up with was to move the |
Thanks! Now I understand. When I learnt nodestreams, it worked the way I described! emitting lots of drain events will still work correctly with old streams. unfortunately they can't describe the state of a node stream with a finite state machine now! you have to have a stack-based automaton. but if node uses a counter here, I think we should use a counter too, even if we emit drain inside a loop |
as I think about this more, I realize that actually that change in node streams would not be backwards compatible with older node streams. I think we better figure out what is really going on here |
for reference, this is the commit that introduced that feature nodejs/node@0f8de5e |
Found the original referenced issue with discussion: nodejs/node-v0.x-archive#5860 |
What exactly do you think break compat here, and to which streams version?
do you think this is not true anymore, or just the implementation in here? |
I'm a bit confused by this drain counter thing. Although, maybe ... it would make sense if it's for when you pipe a stream to multiple destinations? I'm gonna study your test code and figure out what is going on there |
oh, now I see it. this is a big no-no d5b8ffd#diff-168726dbe96b3ce427e7fedce31bb0bcR68 the problem here is that you have emitted the event, then updated the state, but it should be the other way around. You must be very careful with this, because the anything (sync) can happen during the event listener, including triggering other events. In this case, you emit the drain event, which triggers more writes, etc, but the stream still thinks it's no longer needing to drain, when actually, it may have reentered the needDrain state. if you just shift the |
f76c7e5
to
43a3266
Compare
@dominictarr rebased based on your changes and passes all my integration tests :) |
cool, merging! |
@dominictarr I think you published without pushing to github :) |
Hey! Just to confirm, has this been merged? Seems that there is a new version on npm, but the last commit in github master is from 6 days ago |
yes, sorry - I just forgot which branch I was on. |
merged into 1.3.2 |
Thank you 🙂 |
Trying to work out a test for this, which I will hopefully push soon