Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upstream: fix readable behavior for highWaterMark === 0 #21690
Conversation
nodejs-github-bot
added
the
stream
label
Jul 6, 2018
This comment has been minimized.
This comment has been minimized.
|
/cc @nodejs/streams |
lundibundi
force-pushed the
lundibundi:fix-stream-stdin
branch
from
ab7ddcd
to
d14752c
Jul 6, 2018
addaleax
requested a review
from
mcollina
Jul 10, 2018
This comment has been minimized.
This comment has been minimized.
|
ping @mcollina. |
This comment has been minimized.
This comment has been minimized.
lundibundi
force-pushed the
lundibundi:fix-stream-stdin
branch
from
d14752c
to
4df321c
Jul 30, 2018
This comment has been minimized.
This comment has been minimized.
|
Well, CI has failed due to my test... I'm not sure how to handle tty stdin on CI, as it works fine locally. It seems to close the stdin even before the setTimeout fires, can someone help? Should I |
BridgeAR
reviewed
Jul 30, 2018
| r.push(null); | ||
|
|
||
| r.once('readable', common.mustCall()); | ||
| r.once('end', common.mustCall()); |
This comment has been minimized.
This comment has been minimized.
BridgeAR
Jul 30, 2018
Member
When reading the description of the test it seems like these should be .on instead of once?
| const assert = require('assert'); | ||
|
|
||
| // This test ensures that Node.js will not ignore tty 'readable' subscribers | ||
| // when it's the only tty subscriber and te only thing keeping event loop alive |
This comment has been minimized.
This comment has been minimized.
BridgeAR
reviewed
Jul 30, 2018
|
If you want to actually test a tty you have to move the test in the corresponding tty test folder. Otherwise it's not detected as try. |
This comment has been minimized.
This comment has been minimized.
|
@BridgeAR thanks a lot, I've missed that. Should be fixed now. |
BridgeAR
reviewed
Jul 30, 2018
|
|
||
| r.push(null); | ||
|
|
||
| r.once('readable', common.mustCall()); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
lundibundi
Jul 30, 2018
Author
Member
Thanks, idk why did I think it was okay to put once on both of them.
BridgeAR
requested a review
from
mafintosh
Jul 30, 2018
This comment has been minimized.
This comment has been minimized.
mcollina
approved these changes
Aug 6, 2018
|
code LGTM. Can land if citgm does not report additional breakage. |
mcollina
added
the
author ready
label
Aug 6, 2018
This comment has been minimized.
This comment has been minimized.
|
Seems good, but CITGM is currently not very healthy: nodejs/build#1429. |
This comment has been minimized.
This comment has been minimized.
|
I'm not I understand why this is needed for TTYs to work? Can someone clarify this for me? The unneeded readables was breaking of code for me, and as I understand this, it restores that behaivor? |
mcollina
removed
the
author ready
label
Aug 8, 2018
This comment has been minimized.
This comment has been minimized.
|
@mafintosh After your comment, I went to double check and found a better way of tackling this problem. But I also discovered the other thing. Your PR is indeed fixing the issue of empty-readable but the thing is, it suppresses the issue by not emitting the event but there are still multiple calls to The thing is that with the write pattern as in
there are 2 more 'emit readable rStream' that were suppressed and I think at least the second one shouldn't have happened at all (the first one is from the latest data push). |
lundibundi
force-pushed the
lundibundi:fix-stream-stdin
branch
from
ce3551e
to
e874f79
Aug 9, 2018
lundibundi
changed the title
stream: emit empty readable event to lone listener
stream: change behavior for highWaterMark === 0
Aug 9, 2018
This comment has been minimized.
This comment has been minimized.
|
@mcollina @mafintosh @BridgeAR I'd like another review as I changed this PR's idea. |
mcollina
requested changes
Aug 10, 2018
|
Can you add some tests that shows the changed behavior in streams? I'd like to see a a test that failed in current master but passes here. I think we would need to add some docs for (Using the big red cross because I approved it in the past) |
| @@ -274,7 +274,9 @@ function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) { | |||
| // Also, if we have no data yet, we can stand some more bytes. | |||
| // This is to work around cases where hwm=0, such as the repl. | |||
This comment has been minimized.
This comment has been minimized.
| @@ -383,7 +385,8 @@ Readable.prototype.read = function(n) { | |||
| // the 'readable' event and move on. | |||
This comment has been minimized.
This comment has been minimized.
mcollina
added
the
semver-major
label
Aug 10, 2018
This comment has been minimized.
This comment has been minimized.
|
It's not really clear what it is changing here. Can you describe it the change to streams a bit more? |
lundibundi
force-pushed the
lundibundi:fix-stream-stdin
branch
from
e874f79
to
e5a6527
Aug 10, 2018
This comment has been minimized.
This comment has been minimized.
|
@mcollina cleaned up the PR (and removed redundant checks) and added relevant test without the TTY. Yeah, this shouldn't change anything, it's a bug fix, bad wording, sorry. I've updated the description. P.s. Streams sure are tough, thanks for bearing with me. |
lundibundi
changed the title
stream: change behavior for highWaterMark === 0
stream: fix readable behavior for highWaterMark === 0
Aug 10, 2018
mcollina
removed
the
semver-major
label
Aug 10, 2018
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Thanks for taking these issue, they are indeed! |
mcollina
approved these changes
Aug 10, 2018
This comment has been minimized.
This comment has been minimized.
|
Very nice fix in the end |
mafintosh
approved these changes
Aug 10, 2018
BridgeAR
approved these changes
Aug 10, 2018
BridgeAR
added
the
author ready
label
Aug 10, 2018
This comment has been minimized.
This comment has been minimized.
|
Landed in fe47b8b |
mcollina
closed this
Aug 10, 2018
This comment has been minimized.
This comment has been minimized.
|
Thanks @lundibundi for tackling this one! |
lundibundi commentedJul 6, 2018
•
edited
Avoid trying to emit 'readable' due to the fact that
state.length is always >= state.highWaterMark if highWaterMark is 0.
Therefore upon .read(0) call (through .on('readable')) stream assumed
that it has enough data to emit 'readable' even though
state.length === 0 instead of issuing _read(). Which led to the TTY
not recognizing that someone is waiting for the input.
Fixes: #20503
Refs: #18372
Checklist
make -j4 test(UNIX) passesI put one test under sequential as it uses process.stdin to emulate the use case and I'm not sure if that is correct.
Edit: I've changed the PR title and description according to changes.