-
Notifications
You must be signed in to change notification settings - Fork 30k
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: readable stream continues to read when pushing a empty string #18211
stream: readable stream continues to read when pushing a empty string #18211
Conversation
ping @nodejs/streams @mcollina |
From reading your test I'm not sure I completely understand what the problem is? |
@mafintosh From the view of a nodejs user, I think a readable stream should end if only calling
But if |
I am 👎 to this change. |
Yes, I'm agreeing with @mcollina as well. Stream termination should be as explicit as possible. I think we should consider having an explicit API for it at some point. |
@mcollina @mafintosh My purpose may be misunderstood. I updated the test so that you can better understand it. I am so sorry for my poor english. |
We can just consider that |
Here are some automated runs: CI: https://ci.nodejs.org/job/node-test-pull-request/12611/ Anyway, if we want to relax this it needs to be done earlier: https://github.com/MoonBall/node/blob/49ed0814f2750075fb64ab167f9a129f70f37d52/lib/_stream_readable.js#L234 esplicitly checks for a string longer than zero. This check was made pretty explicit, so if we want to make this change we should edit it there. I'm not super-confident in adding cc @mafintosh? |
The linter seems to have failed with:
|
Can you also rebase on top of master? |
ok. |
eef4179
to
9547feb
Compare
Rebased. |
What happens if you push |
@mcollina
The error is:
I doesn't fix it, because I think |
9547feb
to
aaf9bc7
Compare
@mcollina I modified the code because that |
I'm not super convinced by this change, I'll have more time to review it in a week. @mafintosh can you check this? |
Let me try and look into it tonight |
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.
I'm not convinced that changing this is the right thing to do, yet. Maybe somebody else should weight in on why.
BTW, this is semver-major.
My bad with the tests, was using the wrong branch. They pass. |
@MoonBall what happens if you do |
@mafintosh The result is same if I |
|
||
r.on('readable', () => { | ||
const data = r.read(); | ||
if (data !== null) result += data; |
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.
could you collect the chunks in an array and deepEqual those and the end instead of the concatenated string? That'd make it a bit easier for me (and others) to understand and show that it isn't returning an empty string here ever :)
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.
There is a misunderstanding. This change only fixed that the 'end' event isn't emitted when we push a empty string, a empty buffer or undefined
.
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.
Currently, a readable stream in non-object mode doesn't inform users a empty string or a empty buffer. It is reasonable.
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.
I'd like it if the test was a bit more explicit.
result += data
doesn't tell me if r.read()
returns an empty buffer, which from reading the test, you might expect.
Doing result.push(data)
and then on end assert.deepEquals(result, [...])
would help
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.
@mafintosh I did it.
aaf9bc7
to
29554ed
Compare
29554ed
to
77a66d3
Compare
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.
LGTM
Landing |
Landed as faeee11. |
PR-URL: #18211 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
PR-URL: nodejs#18211 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
stream