classification
Title: Add macOS TCP_KEEPALIVE to available socket options
Type: enhancement Stage: patch review
Components: Extension Modules Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Ma Lin, llawall, steve.dower
Priority: normal Keywords: patch

Created on 2018-10-08 13:38 by llawall, last changed 2018-10-15 20:31 by llawall.

Pull Requests
URL Status Linked Edit
PR 9759 open python-dev, 2018-10-08 13:42
Messages (5)
msg327351 - (view) Author: Robert Wall (llawall) Date: 2018-10-08 13:38
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.
msg327441 - (view) Author: Robert Wall (llawall) Date: 2018-10-09 21:58
Acknowledging the test failure and message pointing to #32394:

======================================================================
FAIL: test_new_tcp_flags (test.test_socket.TestMSWindowsTCPFlags)
----------------------------------------------------------------------
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 #32394. Any thoughts on this one?
msg327450 - (view) Author: Ma Lin (Ma Lin) * Date: 2018-10-10 01:53
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
msg327656 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2018-10-13 16:10
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.
msg327782 - (view) Author: Robert Wall (llawall) Date: 2018-10-15 20:31
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 #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
[2] https://msdn.microsoft.com/en-us/library/windows/desktop/dd877220(v=vs.85).aspx
[3] https://docs.microsoft.com/en-us/windows/desktop/winsock/ipproto-tcp-socket-options
History
Date User Action Args
2018-10-15 20:31:49llawallsetmessages: + msg327782
2018-10-13 16:10:48steve.dowersetmessages: + msg327656
2018-10-10 01:53:47Ma Linsetnosy: + Ma Lin
messages: + msg327450
2018-10-09 21:58:19llawallsetversions: + Python 3.6, Python 3.7
nosy: + steve.dower

messages: + msg327441

components: + Extension Modules, - Library (Lib)
2018-10-08 13:42:30python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request9144
2018-10-08 13:38:10llawallcreate