GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: fix readable behavior for highWaterMark === 0 by lundibundi · Pull Request #21690 · nodejs/node

Conversation

@lundibundi

@lundibundi lundibundi commented Jul 6, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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) passes
  • tests and/or benchmarks are included
    I put one test under sequential as it uses process.stdin to emulate the use case and I'm not sure if that is correct.
  • documentation is changed or added (not sure what to change)
  • commit message follows commit guidelines

Edit: I've changed the PR title and description according to changes.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@nodejs-github-bot nodejs-github-bot added the stream Issues and PRs related to Node.js streams. label Jul 6, 2018
@mscdex

mscdex commented Jul 6, 2018

Copy link
Copy Markdown
Contributor

/cc @nodejs/streams

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lundibundi
lundibundi force-pushed the fix-stream-stdin branch from ab7ddcd to d14752c Compare July 6, 2018 21:09
@addaleax
addaleax requested a review from mcollina July 10, 2018 22:37
@lundibundi

lundibundi commented Jul 19, 2018

Copy link
Copy Markdown
Member Author

ping @mcollina.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mcollina

mcollina commented Jul 30, 2018

Copy link
Copy Markdown
Member

CI: https://ci.nodejs.org/job/node-test-pull-request/16075/
CITGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1473/
CITGM (master): https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1474/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lundibundi
lundibundi force-pushed the fix-stream-stdin branch from d14752c to 4df321c Compare July 30, 2018 17:45
@lundibundi

lundibundi commented Jul 30, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

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 fork a process for this test and only connect stderr to pass the error?
I've also rebased and decreased delay to 1 ms instead of 1000.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR
BridgeAR reviewed Jul 30, 2018
View reviewed changes
Comment thread test/parallel/test-readable-single-end.js Outdated

@BridgeAR BridgeAR Jul 30, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When reading the description of the test it seems like these should be .on instead of once?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lundibundi reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread test/sequential/test-readable-tty-keepalive.js Outdated

@BridgeAR BridgeAR Jul 30, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in the.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lundibundi reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
BridgeAR
BridgeAR reviewed Jul 30, 2018
View reviewed changes

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lundibundi

lundibundi commented Jul 30, 2018

Copy link
Copy Markdown
Member Author

@BridgeAR thanks a lot, I've missed that. Should be fixed now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR
BridgeAR reviewed Jul 30, 2018
View reviewed changes
Comment thread test/parallel/test-readable-single-end.js Outdated

@BridgeAR BridgeAR Jul 30, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not also just be on?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lundibundi lundibundi Jul 30, 2018

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, idk why did I think it was okay to put once on both of them. 🤔

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@BridgeAR
BridgeAR requested a review from mafintosh July 30, 2018 22:20
@mcollina

mcollina commented Aug 6, 2018

Copy link
Copy Markdown
Member

CI: https://ci.nodejs.org/job/node-test-pull-request/16213/
CITGM (master): https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1481/
CITGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1482/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mcollina
mcollina approved these changes Aug 6, 2018
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code LGTM. Can land if citgm does not report additional breakage.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mcollina mcollina added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Aug 6, 2018
@mcollina

mcollina commented Aug 6, 2018

Copy link
Copy Markdown
Member

Seems good, but CITGM is currently not very healthy: nodejs/build#1429.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mafintosh

mafintosh commented Aug 6, 2018

Copy link
Copy Markdown
Member

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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mcollina mcollina removed the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Aug 8, 2018
@lundibundi

lundibundi commented Aug 9, 2018

Copy link
Copy Markdown
Member Author

@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 emitReadable_ present. I tried to actually resolve the issue but to no avail, unfortunately. Here is the description, maybe someone can figure it out.

The thing is that with the write pattern as in test/parallel/test-stream-readable-no-unneeded-readable.js triggers 'readable' event upon push (as it should) but due to the fact that it only arrives on the nextTick that .once('readable') manages to catch old readable event (because we have already read all of the data of that event in the wrapper) that is now empty and results in empty (and multiple) 'readable' events.
If we look at the debug log (I added a few log statements) we can see that actually after last push (before push(null))

STREAM 15878: do read
wrapper read called
STREAM 15878: read undefined
STREAM 15878: need readable true
STREAM 15878: length less than watermark true
STREAM 15878: do read
wrapper read called
STREAM 15878: read undefined
STREAM 15878: need readable true
STREAM 15878: length less than watermark true
STREAM 15878: do read
STREAM 15878: on readable 0 true
STREAM 15878: read undefined
STREAM 15878: need readable true
STREAM 15878: length less than watermark true
STREAM 15878: reading or ended false
STREAM 15878: emit readable rStream
STREAM 15878: flow null
STREAM 15878: emit readable wrapperStream
STREAM 15878: flow true
STREAM 15878: read undefined
STREAM 15878: need readable false
STREAM 15878: length less than watermark true
STREAM 15878: reading or ended false
STREAM 15878: emit readable rStream
STREAM 15878: flow null
STREAM 15878: emit readable wrapperStream
STREAM 15878: flow true
STREAM 15878: read undefined
STREAM 15878: need readable false
STREAM 15878: length less than watermark true
STREAM 15878: reading or ended false
STREAM 15878: readableAddChunk null
STREAM 15878: emit readable rStream
readable called
STREAM 15878: read undefined
STREAM 15878: endReadable false
STREAM 15878: flow null
STREAM 15878: endReadableNT false 0
STREAM 15878: readableAddChunk null
STREAM 15878: emit readable wrapperStream
STREAM 15878: flow true
STREAM 15878: read undefined
STREAM 15878: endReadable false
STREAM 15878: endReadableNT false 0
STREAM 15878: do read
STREAM 15878: readableAddChunk <Buffer 62 61 72>
STREAM 15878: emitReadable null
STREAM 15878: readableAddChunk <Buffer 62 61 72>
STREAM 15878: emitReadable true
STREAM 15878: read undefined
STREAM 15878: need readable false
STREAM 15878: length less than watermark true
STREAM 15878: do read
wrapper read called
STREAM 15878: read undefined
STREAM 15878: need readable true
STREAM 15878: length less than watermark true
STREAM 15878: do read
STREAM 15878: on readable 0 true
STREAM 15878: read undefined
STREAM 15878: need readable true
STREAM 15878: length less than watermark true
STREAM 15878: reading or ended false
STREAM 15878: emit readable rStream
STREAM 15878: flow null
STREAM 15878: emit readable wrapperStream
STREAM 15878: flow true
STREAM 15878: read undefined
STREAM 15878: need readable false
STREAM 15878: length less than watermark true
STREAM 15878: reading or ended false
STREAM 15878: emit readable rStream
STREAM 15878: flow null
STREAM 15878: emit readable wrapperStream
STREAM 15878: flow true
STREAM 15878: read undefined
STREAM 15878: need readable false
STREAM 15878: length less than watermark true
STREAM 15878: reading or ended false
STREAM 15878: readableAddChunk null
STREAM 15878: emit readable rStream
readable called
STREAM 15878: read undefined
STREAM 15878: endReadable false
STREAM 15878: flow null
STREAM 15878: endReadableNT false 0
STREAM 15878: readableAddChunk null
STREAM 15878: emit readable wrapperStream
STREAM 15878: flow true
STREAM 15878: read undefined
STREAM 15878: endReadable false
STREAM 15878: endReadableNT false 0

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).
Though I may be misunderstanding something and this second read/emit is actually needed?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lundibundi
lundibundi force-pushed the fix-stream-stdin branch from ce3551e to e874f79 Compare August 9, 2018 15:18
@lundibundi lundibundi changed the title stream: emit empty readable event to lone listener stream: change behavior for highWaterMark === 0 Aug 9, 2018
@lundibundi

lundibundi commented Aug 9, 2018

Copy link
Copy Markdown
Member Author

@mcollina @mafintosh @BridgeAR I'd like another review as I changed this PR's idea.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mcollina
mcollina requested changes Aug 10, 2018
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 highWaterMark: 0. There aren't any atm.

(Using the big red cross because I approved it in the past)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/_stream_readable.js Outdated

@mcollina mcollina Aug 10, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to adjust this comment.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/_stream_readable.js Outdated

@mcollina mcollina Aug 10, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment will need an update.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mcollina mcollina added the semver-major PRs that contain breaking changes and should be released in the next major version. label Aug 10, 2018
@mcollina

mcollina commented Aug 10, 2018

Copy link
Copy Markdown
Member

It's not really clear what it is changing here. Can you describe it the change to streams a bit more?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lundibundi
stream: fix readable behavior for highWaterMark === 0
e5a6527
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: nodejs#20503
Refs: nodejs#18372
@lundibundi
lundibundi force-pushed the fix-stream-stdin branch from e874f79 to e5a6527 Compare August 10, 2018 10:56
@lundibundi

lundibundi commented Aug 10, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

@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.
Also, test/parallel/test-readable-single-end.js can be dropped but I see no harm in having more tests.

P.s. Streams sure are tough, thanks for bearing with me.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lundibundi lundibundi changed the title stream: change behavior for highWaterMark === 0 stream: fix readable behavior for highWaterMark === 0 Aug 10, 2018
@mcollina mcollina removed the semver-major PRs that contain breaking changes and should be released in the next major version. label Aug 10, 2018
@mcollina

mcollina commented Aug 10, 2018

Copy link
Copy Markdown
Member

CI: https://ci.nodejs.org/job/node-test-pull-request/16336/

CITGM (master): https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1497/
CITGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1498/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mcollina

mcollina commented Aug 10, 2018

Copy link
Copy Markdown
Member

P.s. Streams sure are tough, thanks for bearing with me.

Thanks for taking these issue, they are indeed!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mcollina
mcollina approved these changes Aug 10, 2018
View reviewed changes
@mafintosh

mafintosh commented Aug 10, 2018

Copy link
Copy Markdown
Member

Very nice fix in the end

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mafintosh
mafintosh approved these changes Aug 10, 2018
View reviewed changes
BridgeAR
BridgeAR approved these changes Aug 10, 2018
View reviewed changes
@BridgeAR BridgeAR added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Aug 10, 2018
@mcollina

mcollina commented Aug 10, 2018

Copy link
Copy Markdown
Member

Landed in fe47b8b

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mcollina mcollina closed this Aug 10, 2018
@mcollina

mcollina commented Aug 10, 2018

Copy link
Copy Markdown
Member

Thanks @lundibundi for tackling this one!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mcollina pushed a commit that referenced this pull request Aug 10, 2018
@lundibundi @mcollina
stream: fix readable behavior for highWaterMark === 0
fe47b8b
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

PR-URL: #21690
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
targos pushed a commit that referenced this pull request Aug 11, 2018
@lundibundi @targos
stream: fix readable behavior for highWaterMark === 0
1c61205
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

PR-URL: #21690
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@rvagg rvagg mentioned this pull request Aug 13, 2018
Release proposal: v10.9.0 #22295
Merged
This was referenced Aug 16, 2018
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-android-nodejs#230
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-nodejs#215
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-android-nodejs#231
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-nodejs#216
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-android-nodejs#232
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-nodejs#217
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-android-nodejs#233
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-nodejs#218
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-android-nodejs#234
Closed
2018-08-15 Version 10.9.0 (Current) @rvagg beevelop/docker-nodejs#219
Closed
@ZYSzys ZYSzys mentioned this pull request Dec 21, 2018
readable event,outputs are different between v9.11 and v10.14.2 #25158
Closed
firass111 pushed a commit to firass111/Project_node1 that referenced this pull request Apr 16, 2025
@lundibundi @rvagg
stream: fix readable behavior for highWaterMark === 0
31e3e6f
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: nodejs/node#20503
Refs: nodejs/node#18372

PR-URL: nodejs/node#21690
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mcollina mcollina mcollina approved these changes
@BridgeAR BridgeAR BridgeAR approved these changes
+1 more reviewer
@mafintosh mafintosh mafintosh approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. stream Issues and PRs related to Node.js streams.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@lundibundi @mscdex @mcollina @mafintosh @BridgeAR @nodejs-github-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.