| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Sorry, something went wrong.
Sorry, something went wrong.
|
Since this already had a few approvals I'm not going to block it but in my opinion this:
I see only disadvantages. |
Sorry, something went wrong.
|
Commit message title and body should be updated as they are misleading. There is no _finished property. |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
@lpinca I find myself agreeing more than disagreeing with your points. If you were trying to adjust this code in the spirit of #445, what would you recommend? (I can think of a few things, but opted for this as it didn't involve adding new stuff to the stream module, which I would expect to meet resistance.) Or is #445 mostly misguided in your view? |
Sorry, something went wrong.
|
I would add a getter to Writable.prototype like
but yes I think #445 is a bit misguided because it means exposing most (if not all) attributes of ReadableState and WritableState. There are cases also in userland where you really need to read those properties. end-of-stream is just an example. I think _readableState and _writableState should be public and documented as "use at your own risk". |
Sorry, something went wrong.
Hey, @nodejs/streams, what do you think?
|
Sorry, something went wrong.
|
(Is @nodejs/streams the wrong team to ask? Who is the right team?) |
Sorry, something went wrong.
There was a problem hiding this comment.
Note sure if the callback can be called synchronously? Just to be safe... put it after the end() call? i.e. keep the order as it was
Sorry, something went wrong.
There was a problem hiding this comment.
eos() unconditionally adds one listener for the 'finish' event and one for 'close' event (and actually another for 'end' event even if the readable option is false).
If _writableState.finished is already true then the 'finish' event won't be emitted and it will wait for 'close'. Even if this is emitted synchronously it is not a problem because it means the socket is already destroyed and no longer writable.
If _writableState.finished is false then the 'finish' event won't be emitted until socket.end() is called and if this already happened then the socket is no longer writable.
So the order should not matter. However I can see a case where the behavior is different.
'use strict';
const net = require('net');
const server = net.createServer(function(socket) {
socket.write('foo');
});
server.listen(function() {
const socket = net.connect(this.address().port, function() {
socket.on('finish', function() {
socket.destroySoon();
});
socket.on('close', function() {
console.log('close');
});
setTimeout(function() {
socket.end();
}, 100);
});
});Yes, it's a fabricated example that probably will never happen in reality but with this patch the socket is not destroyed ('close' is not emitted) until the buffered data is actually read. This is not the case with the current implementation of destroySoon().
Sorry, something went wrong.
Accessing _readableState and _writableState directly is really a bad idea. They contain our buffering system, and those should not really be touched. I fully agree on #445.
I'm +1 to that approach (#27974 (comment)).
I'm +1 to this PR as well. However I concur that finished does a lot of things, and adding a getter would be the most performant way to solve the problem.
@nodejs/streams is likely the team to target for this question. |
Sorry, something went wrong.
I think if someone messes with the internal buffers it means they either know what they are doing or want to break things intentionally. This is the reason for "use at your own risk". Take this data for example https://github.com/search?p=1&q=_readableState&type=Code, just from the first results we see use of
Yes, exposing all of that via getters is an option, but it does not seem the right solution to me. |
Sorry, something went wrong.
|
Marking this WIP for now but if someone else wants to open a PR that does this the "right" way before I get around to it, by all means, please do. |
Sorry, something went wrong.
Sorry, something went wrong.
|
Used the writableFinished property as implemented by @zero1five in #28007. Removed WIP label. I think this is ready for re-reviews. |
Sorry, something went wrong.
Sorry, something went wrong.
|
(@addaleax Sorry, I didn't meant to request a re-review from you since you had already re-reviewed, but I don't see a way to undo my request in the GitHub interface.) |
Sorry, something went wrong.
Replace usage of quasi-private _writableState.finished with public writableFinished property. PR-URL: #27974 Refs: #445 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
| Back | FazBrowse Home | New Git URL |
Replace use of quasi-private streams _writableState property in net.js with
use of the public streams finished() method.
Refs: #445
Checklist