The Wayback Machine - https://web.archive.org/web/20220422155406/https://github.com/libuv/libuv/pull/3488
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: set tcp keepalive delay only if > 0 #3488

Open
wants to merge 5 commits into
base: v1.x
Choose a base branch
from

Conversation

Copy link

@cc-int3 cc-int3 commented Feb 16, 2022

If tcpkeepalive delay is zero, don't set the TCP_KEEPALIVE sock option.
This will result in a) using the windows system settings or b) if
previously set, no change.

If tcpkeepalive delay is zero, don't set the TCP_KEEPALIVE sock option.
This will result in a) using the windows system settings or b) if
previously set, no change.
@cc-int3
Copy link
Author

@cc-int3 cc-int3 commented Feb 16, 2022

for issue #3487

@vtjnash
Copy link
Member

@vtjnash vtjnash commented Feb 17, 2022

Can you add a simple test (showing that it returns successfully) and change the unix code to match? The discussion in #3487 is ongoing still, but that would push this towards a state where it can be reviewed in tandem.

@cc-int3
Copy link
Author

@cc-int3 cc-int3 commented Feb 17, 2022

Sure, it'll take a day or so

Ensure that uv_tcp_keepalive will accept a delay value of 0
( meaning use previous set value, or system default, if not previously
set )
@cc-int3
Copy link
Author

@cc-int3 cc-int3 commented Feb 17, 2022

added additional tests to existing file.
Linux behavior and windows behavior match (with respect to delay)

Copy link
Member

@saghul saghul left a comment

A tiny nit, LGTM otherwise.

docs/src/tcp.rst Outdated
ignored when `enable` is zero.
ignored when `enable` is zero.
A `delay` of 0 will imply using the system default setting for tcp keepalives,
Copy link
Member

@saghul saghul Feb 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A `delay` of 0 will imply using the system default setting for tcp keepalives,
A `delay` of 0 will imply using the system default setting for TCP keepalives,

Copy link
Author

@cc-int3 cc-int3 Feb 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@saghul
Copy link
Member

@saghul saghul commented Mar 3, 2022

I think we need this logic for (at least) Linux too: https://github.com/torvalds/linux/blob/f1baf68e1383f6ed93eb9cff2866d46562607a43/net/ipv4/tcp.c#L3313

If you call uv_tcp_keepalive(handle, 1, 0) on a connected socket you get UV_EINVAL on Linux, not so on macOS.

I'd suggest we also apply the delay only if it's > 0 for Unix:

int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
Or maybe we should ignore EINVAL? I guess a platform limitation is that you cannot set the initial delay to something and then want to reset it to the platform default.

Last, the current flags test is insufficient. Because it's applied over an unbound socket, the delay is ignored:

/* TODO Store delay if uv__stream_fd(handle) == -1 but don't want to enlarge
I think we should at least bind it and that will make the above example fail on Linux.

@bnoordhuis WDYT?

test: call bind to get valid socket for tests
@cc-int3
Copy link
Author

@cc-int3 cc-int3 commented Mar 5, 2022

Added requested changes.
I'm torn on not setting TCP_KEEPINTVL and TCP_KEEPCNT to the windows ( and documentation ) values in unix when delay == 0 ( I painted myself into a corner with my 'use system defaults' stance ) I really have no strong feelings about those two settings.

@saghul
Copy link
Member

@saghul saghul commented Mar 6, 2022

Looking good! Do we know what other platforms do when trying to set the delay to 0? We now know Windows resets it and Linux errors out.

@cc-int3
Copy link
Author

@cc-int3 cc-int3 commented Mar 12, 2022

I don't have access to any other platforms, so I'm not sure how to answer. I thought I saw an issue with keepalives on an IBM OS during my original search, but I can't seems to find it now. Sorry I can't be of more help.

@stale
Copy link

@stale stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

@stale stale bot added the stale label Apr 16, 2022
@saghul
Copy link
Member

@saghul saghul commented Apr 16, 2022

I'll try to look at what the FreeBSD kernel does shortly.

@stale stale bot removed the stale label Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants