Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rustyconover
Copy link
Contributor

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), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Rationale

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 to
setsockopt() that are unnecessary since the socket has already been set to
send keep alive packets.

This is much like #31543

@nodejs-github-bot nodejs-github-bot added the net Issues and PRs related to the net subsystem. label Jan 28, 2020
@rustyconover rustyconover requested a review from ronag February 3, 2020 05:44
lib/net.js Show resolved Hide resolved
@rustyconover rustyconover force-pushed the fix-suppress-multiple-set-keepalive branch from 4b2477c to 96043fc Compare February 17, 2020 17:31
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.
@rustyconover rustyconover force-pushed the fix-suppress-multiple-set-keepalive branch from 96043fc to f3fac17 Compare March 2, 2020 01:41
@rustyconover rustyconover requested a review from jasnell March 2, 2020 01:42
if (msecs != null && typeof msecs !== 'number')
throw new ERR_INVALID_ARG_TYPE('msecs', 'number', msecs);

if (msecs === 0) {
Copy link
Member

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) {
Copy link
Member

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?

@BridgeAR BridgeAR force-pushed the master branch 2 times, most recently from 8ae28ff to 2935f72 Compare May 31, 2020 12:19
@rustyconover rustyconover requested a review from a team as a code owner August 10, 2020 16:07
@rustyconover rustyconover requested a review from a team August 10, 2020 16:07
Copy link
Member

@mcollina mcollina left a 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?

@aduh95 aduh95 added the stalled Issues and PRs that are stalled. label Nov 8, 2020
@github-actions
Copy link
Contributor

github-actions bot commented Nov 8, 2020

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.

@rustyconover
Copy link
Contributor Author

Let's leave this open until someone contributes a test or decides to merge without.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
net Issues and PRs related to the net subsystem. stalled Issues and PRs that are stalled.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants