| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
From reading your test I'm not sure I completely understand what the problem is? |
Sorry, something went wrong.
|
@mafintosh From the view of a nodejs user, I think a readable stream should end if only calling read() in a 'readable' listener. The key code is as below: const r = new Readable();
r.on('readable', () => {
r.read();
});
r.on('end', () => {
// calling `read()` in a 'readable' listener should ultimately emit the 'end' event.
});
But if _read() pushes a empty string or undefined, the key code doesn't emit the 'end' event. But I'm not sure that the situation exists. It can be avoided by stream implementors. |
Sorry, something went wrong.
|
I am 👎 to this change. undefined is a legit value in object mode stream, and it should not terminate. |
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
|
@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. |
Sorry, something went wrong.
|
We can just consider that this.push() pushes a empty string. I updated the title of the PR. |
Sorry, something went wrong.
|
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 '' as a valid chunk, because you have actually written nothing and the stream knows it should push things. However I see why it could improve the API. cc @mafintosh? |
Sorry, something went wrong.
|
The linter seems to have failed with:
|
Sorry, something went wrong.
Sorry, something went wrong.
|
Can you also rebase on top of master? |
Sorry, something went wrong.
|
ok. |
Sorry, something went wrong.
|
Rebased. |
Sorry, something went wrong.
|
@mcollina In non-objectMode, we can call this.push() without a param. Is it valid? I fixed that pushing undefined in another PR(#18244). |
Sorry, something went wrong.
|
What happens if you push undefined with this change? |
Sorry, something went wrong.
Sorry, something went wrong.
|
@mcollina if (typeof chunk !== 'string' &&
!state.objectMode &&
Object.getPrototypeOf(chunk) !== Buffer.prototype) {
chunk = Stream._uint8ArrayToBuffer(chunk);
}
The error is: _stream_readable.js:237
Object.getPrototypeOf(chunk) !== Buffer.prototype) {
^
TypeError: Cannot convert undefined or null to object
at Function.getPrototypeOf (<anonymous>)
at readableAddChunk (_stream_readable.js:237:18)
at Readable.push (_stream_readable.js:215:10)
I doesn't fix it, because I think undefined is invalid. But, if we allow to push undefined in non-object mode, I will fix it. |
Sorry, something went wrong.
|
@mcollina I modified the code because that push() maybe pass a undefined chunk. |
Sorry, something went wrong.
|
I'm not super convinced by this change, I'll have more time to review it in a week. @mafintosh can you check this? |
Sorry, something went wrong.
|
Let me try and look into it tonight |
Sorry, something went wrong.
Sorry, something went wrong.
There was a problem hiding this comment.
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.
Sorry, something went wrong.
|
@MoonBall @mcollina The tests doesn't pass for me when rebasing on top of latest master, do they for you? Also the test isn't completely clear still imo. Does this make it emit an empty string on read? |
Sorry, something went wrong.
|
My bad with the tests, was using the wrong branch. They pass. |
Sorry, something went wrong.
|
@MoonBall what happens if you do push(Buffer.alloc(0)) ? |
Sorry, something went wrong.
|
@mafintosh The result is same if I push() a empty Buffer, a empty string or undefined because of the condition. |
Sorry, something went wrong.
There was a problem hiding this comment.
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 :)
Sorry, something went wrong.
There was a problem hiding this comment.
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.
Sorry, something went wrong.
There was a problem hiding this comment.
Currently, a readable stream in non-object mode doesn't inform users a empty string or a empty buffer. It is reasonable.
Sorry, something went wrong.
There was a problem hiding this comment.
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
Sorry, something went wrong.
There was a problem hiding this comment.
@mafintosh I did it.
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
|
CITGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1290/ |
Sorry, something went wrong.
|
Landing |
Sorry, something went wrong.
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>
| Back | FazBrowse Home | New Git URL |
Checklist
Affected core subsystem(s)
stream