Fixed double-writes when write() is called during 'drain' event#22
Fixed double-writes when write() is called during 'drain' event#22cboden merged 1 commit intoreactphp:masterfrom
Conversation
There was a problem hiding this comment.
Not sure I follow, are these assignments required only in the testing environment to prevent actual writes? Some background info and/or documentation would be much appreciated! 👍
There was a problem hiding this comment.
Yes, I duplicated what testDrain() was doing; it does this to simulate a stream that's not immediately available for writes.
|
Awesome, thanks for spotting and filing this PR! 👍 See my above remark about the test case, otherwise this LGTM 👍 |
|
Thanks for clearing this up @arnaud-lb! LGTM 👍 |
IMO this is indeed a major issue. 👍 for getting this in sooner rather than later Ping @cboden, @WyriHaximus |
|
LGTM 👍 |
Fixed double-writes when write() is called during 'drain' event
|
Thanks @arnaud-lb! Great work! |
When
write()is called in the event handler of adrainevent,Buffercan write things twice.Example:
This write
"foo\nfoo\nbar\n"instead of just"foo\nbar\n".This doesn't happen if
$buffer->write("bar\n");is called on the next tick (which explains why it usually works).This happens in actual code, e.g. when using
Util::pipe()on a Readable which immediately emits a'data'event whenresume()is called.This PR fixes this by updating the internal buffer before emitting the
drainevent.