-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
net: use actual Timeout instances on Sockets #11154
Conversation
lib/net.js
Outdated
for (var s = this; s !== null; s = s._parent) | ||
timers._unrefActive(s); | ||
for (var s = this; s !== null; s = s._parent) { | ||
// if (!s._timeout || s._timeout._idleTimeout === -1) continue; |
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 remove the commented code.
lib/net.js
Outdated
timers._unrefActive(s); | ||
for (var s = this; s !== null; s = s._parent) { | ||
// if (!s._timeout || s._timeout._idleTimeout === -1) continue; | ||
if (!s._timeout) continue; |
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.
Maybe a result of the commented code, but this could be
if (s._timeout)
timers._unrefActive(s._timeout);
14bebdf
to
18ef0d0
Compare
Ah right, forgot to remove that before PRing. Updated, new CI: https://ci.nodejs.org/job/node-test-pull-request/6203/ |
lib/net.js
Outdated
@@ -133,6 +134,7 @@ function Socket(options) { | |||
this._handle = null; | |||
this._parent = null; | |||
this._host = null; | |||
this._timeout = 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.
Rather than introducing yet another _
prefixed property, I'd much prefer to use a Symbol.
Also, given that I'm following an identical pattern in the http2 work, I'd like that Symbol to be reusable (perhaps as an export off the internal/timers.js
this PR creates
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.
Isn't that part of the implementation of a Timeout instance? i.e. didn't a socket already have it, it just wasn't declared in the constructor?
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.
Not that I'm able to see. There are zero hits anywhere in the source for a _timeout
property
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.
It gets added if Socket#setTimeout() is called iirc https://github.com/nodejs/node/blob/master/lib/net.js#L330
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.
Again, not that I'm able to see: https://github.com/nodejs/node/blob/master/lib/timers.js#L296-L317
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.
Apologies, I was thinking of ._idleTimeout
. Disregard
It should be noted that in situations where timer properties were previously available on the Socket object, they will not be after this patch. I highly doubt people rely on those though, since they may not always be there to begin with. |
lib/internal/timers.js
Outdated
const timers = require('timers'); | ||
|
||
// Timeout values > TIMEOUT_MAX are set to 1. | ||
const TIMEOUT_MAX = 2147483647; // 2^31-1 |
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 timers.js
re-use this value by importing it from here?
Isn't this semver-major? |
I think I would lean more towards semver-major on this, just to be careful |
+1 to Semver-major |
Theoretically |
Addressed most of the remaining comments. @jasnell I made the new property hidden using a |
We should be safe but if someone really needed that access then adding a new API shouldn't be out of the question. |
@Fishrock123 ... ping... what's the status on this one? |
Ugh, I'm just worried that we will end up breaking some module or something. Would anyone be calling e.g. ... new CI: https://ci.nodejs.org/job/node-test-pull-request/6985/ Guess we might as well land if it looks good. @nodejs/ctc if anyone else has significant reservations. |
Can the new internal module use the |
768f5ec
to
3c49be6
Compare
@mscdex Done, updated and rebased. |
lib/internal/timers.js
Outdated
|
||
if (msecs < 0 || !isFinite(msecs)) { | ||
throw new RangeError('"msecs" argument must be ' + | ||
'a non-negative finite number, was ' + msecs); |
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 prefer 'positive, finite number'. I recall having a similar discussion in a previous PR about using 'non-negative' vs 'positive' in error messages. To me it sounds more straight-forward.
As far as including the original value in the error message goes, I don't know if we've "standardized" on how it's presented, but to me the current wording is a little awkward. Perhaps it could be more explicit, like
'... must be a positive, finite number. Saw value: ' + msecs
or
'... must be a positive, finite number. Received value: ' + msecs
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.
Zero is an allowed value but is not a positive number, though.
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.
Zero can be positive or negative, at least as far as Javascript is concerned.
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.
FWIW here was the previous PR I had in mind where "non-negative" was dropped in favor of "positive": #10769
@mscdex Does any of this really matter, since it is internal anyways? |
I think to check the performance difference of these changes, we'd need to either create a new benchmark or possibly run one of the http benchmarks (since timeouts may be used there) because those in benchmarks/net do not exercise |
@Fishrock123 What do you mean "any of this?" |
Just to add, just because this function is internal does not mean suggestions should be ignored, especially because functions like |
@Fishrock123 this needs a rebase |
I am closing this due to long inactivity and no response. @Fishrock123 please reopen if you would like to follow up on this. |
This is something I am still interested in pursuing in the very near future. |
Still very busy but on my short-term todo list |
8ca9329
to
0113d10
Compare
@Fishrock123 I did not fully check if all comments were addressed or if you just rebased. Could you have another look? :-) |
FUN FACT: this patch still needed all those internal checks! ... |
0113d10
to
606abb3
Compare
This should fail: https://ci.nodejs.org/job/node-test-pull-request/11650/ I can't get these to pass, I'm not sure why a Edit: to clarify, it fails to parse the request chunk... somehow.
cc @nodejs/http |
All type checking done in this patch is necessary for consistency with other parts of the code. If you want it changed open a separate PR. |
Just gona open a new PR. |
This makes
net.Socket
s use actualTimeout
objects in a_timeout
property, rather than making the socket itself a timer and appending properties to it directly.This should make the code generally easier to understand, and might also prevent some deopts from properties being changes on the socket itself.
It is possible this could effect performance either better or worse, but I highly doubt it would be a significant difference. I'll try to run benchmarks on it in the coming days, but if anyone else would like to that would also be appreciated.
This also exposes
timers.Timeout
so as to avoid a circular dependency with the newlib/internal/timers.js
, but we might not want that so I should be able to refactor more of timers into the internals file if necessary. Tagging assemver-minor
for now due to this. I could also split that into separate commits.Made live on https://twitch.tv/nodesource
CI: https://ci.nodejs.org/job/node-test-pull-request/6202/
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
net, timers