-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
stream: make sure readable is called on empty chunk followed by eof #29762
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const makeDuplexPair = require('../common/duplexpair'); | ||
|
||
const { clientSide, serverSide } = makeDuplexPair(); | ||
|
||
serverSide.resume(); | ||
serverSide.on('end', function(buf) { | ||
serverSide.write('out'); | ||
serverSide.write(''); | ||
serverSide.write(''); | ||
serverSide.end(); | ||
}); | ||
|
||
clientSide.end(); | ||
|
||
clientSide.on('data', common.mustCall()); | ||
clientSide.on('end', common.mustCall()); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ class TestReader extends R { | |
} | ||
|
||
const reader = new TestReader(); | ||
setImmediate(function() { | ||
process.nextTick(function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test kind of contradicts the added test, i.e. it expects the stream to stop reading after pushing an empty chunk. Not sure if this is something that indicates whether this fix will cause other problems. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please articulate this a bit more? Is this change needed to make the test pass? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, otherwise it live locks. Basically it gets into an infinite loop (with nextTick) between. Because it pushes an empty chunk, which invokes a read call which pushes an empty chunk etc... By changing it to nextTick instead of setImmediate it's possible to get between that loop and end it. But as I wrote I'm unsure of the implications. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should avoid that live lock in code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What does that mean in practice? Should we add a guard? Or is the current state of the PR ok in that regard? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think @mcollina would like to add a guard in the streams implementation that this can not cause an infinite loop / that this test does not need to change. |
||
assert.strictEqual(ondataCalled, 1); | ||
console.log('ok'); | ||
reader.push(null); | ||
|
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.
@mcollina: Please also observe this change. I'm pretty sure it's fine but just making sure I have a second opinion on that.