-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
Add macOS TCP_KEEPALIVE to available socket options #79113
Comments
macOS uses TCP_KEEPALIVE in place of TCP_KEEPIDLE. It would be good to have this available in the socket library to use directly. Pull request coming up. |
Acknowledging the test failure and message pointing to bpo-32394: ====================================================================== Traceback (most recent call last):
File "C:\projects\cpython\lib\test\test_socket.py", line 5992, in test_new_tcp_flags
self.assertEqual([], unknown,
AssertionError: Lists differ: [] != ['TCP_KEEPALIVE']
Second list contains 1 additional elements.
First extra element 0:
'TCP_KEEPALIVE'
- []
+ ['TCP_KEEPALIVE'] : New TCP flags were discovered. See bpo-32394 for more information It appears that TCP_KEEPALIVE is defined in Windows (in ws2ipdef.h) despite not being documented on https://docs.microsoft.com/en-us/windows/desktop/winsock/ipproto-tcp-socket-options Given that TCP_KEEPIDLE is #define as the value of TCP_KEEPALIVE, I'd guess that it was added at the same time in which case it probably ought to be added to win_runtime_flags for exclusion based on the same Windows version 1709 too. steve.dower: I've added you to the nosy list based on your active participation in bpo-32394. Any thoughts on this one? |
I searched on Google, an article [1] said: Of note, Mac OS X defines keepidle and keepintvl in terms of milliseconds as opposed to Linux using seconds. On Windows, it's also seconds. Will this option make trouble for cross-platform programs? [1] http://coryklein.com/tcp/2015/11/25/custom-configuration-of-tcp-socket-keep-alive-timeouts.html |
Yes, looks like TCP_KEEPIDLE is only available from 1709, so it should get the same handling as the TCP_KEEPCNT. If TCP_KEEPALIVE is just a synonym, then it applies for both. |
I saw that article too but reading man tcp(4) [1], it says that this value is in seconds for macOS and testing appears to confirm this. Where the unit of time is different, however, is with the old and new Windows keepalive options discussed in bpo-32394. The SIO_KEEPALIVE_VALS set via the WinSock ioctl is in milliseconds [2] whereas the newer TCP_KEEP* flags are set in seconds [3] but this doesn't seem too bad as they are different interfaces. I'll add the tcp_keepalive flag to the same win_runtime_flags structure as the other options with minimum version 1709 and update the failing test accordingly to take account of the new option. [1] https://github.com/apple/darwin-xnu/blob/xnu-4570.1.46/bsd/man/man4/tcp.4#L172 |
I opened a PR to add the socket.TCP_KEEPALIVE flag *on macOS only*. I don't see a reason to add it on Windows since as far as I can tell, TCP_KEEPALIVE is completely undocumented there. Besides there are already two ways to configure keepalive times on Windows (using sock.ioctl+SIO_KEEPALIVE_VALS and using sock.setsockopt+TCP_KEEPIDLE), I don't think we should add a third way. See #25079 |
The TCP_KEEPALIVE socket option for macOS was added in Python 3.10. The previous call count of 3 seems to be incorrect, but wasn't detected since this code was never called previously. python/cpython#79113
The TCP_KEEPALIVE socket option for macOS was added in Python 3.10. The previous call count of 3 seems to be incorrect, but wasn't detected since this code was never called previously. python/cpython#79113
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: