-
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
net: Track state of setKeepAlive and prevent unnecessary system calls #31551
base: main
Are you sure you want to change the base?
net: Track state of setKeepAlive and prevent unnecessary system calls #31551
Conversation
4b2477c
to
96043fc
Compare
The state of .setKeepAlive() is now tracked and code will prevent repeated system calls to setsockopt() when the value has already been set to the desired value for the socket.
96043fc
to
f3fac17
Compare
if (msecs != null && typeof msecs !== 'number') | ||
throw new ERR_INVALID_ARG_TYPE('msecs', 'number', msecs); | ||
|
||
if (msecs === 0) { |
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.
Are you sure this is correct?
if (!this._handle) { | ||
this.once('connect', () => this.setKeepAlive(setting, msecs)); | ||
return this; | ||
} | ||
|
||
if (this._handle.setKeepAlive) | ||
if (this._handle.setKeepAlive && | ||
this[kSetKeepAlive] !== setting) { |
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.
Doesn't this need to include the msec setting as well?
8ae28ff
to
2935f72
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.
Could you add a test?
This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open. |
Let's leave this open until someone contributes a test or decides to merge without. |
The state of .setKeepAlive() is now tracked and code will prevent repeated
system calls to setsockopt() when the value has already been set to the
desired value for the socket.
make -j4 test
(UNIX), orvcbuild test
(Windows) passesRationale
The reason for this change is that if keep alive is set for a HTTP Agent, there will
be repeated calls to
net.Socket.setKeepAlive()
which in turn will cause many calls tosetsockopt() that are unnecessary since the socket has already been set to
send keep alive packets.
This is much like #31543