toolbelt icon indicating copy to clipboard operation
toolbelt copied to clipboard

TCPKeepAliveAdapter will be broken on Windows

Open sigmavirus24 opened this issue 10 years ago • 3 comments

See also: https://bugs.launchpad.net/python-keystoneclient/+bug/1483696

In short, there are some socket constants not defined on Windows.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/25787913-tcpkeepaliveadapter-will-be-broken-on-windows?utm_campaign=plugin&utm_content=tracker%2F418367&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F418367&utm_medium=issues&utm_source=github).

sigmavirus24 avatar Aug 15 '15 03:08 sigmavirus24

Grrrr, Windows!

Lukasa avatar Aug 15 '15 13:08 Lukasa

Even more fun, you can control this stuff on Windows with SIO_SOCKET_VALS (if I'm remembering the constant correctly), but you can't set that with socket.set_option you have to use socket.ioctl which means urllib3's socket_options wouldn't work for this.

sigmavirus24 avatar Aug 15 '15 14:08 sigmavirus24

Looks like you can get around the adapter breaking in windows by monkey patching these two variables:

socket.TCP_KEEPINTVL = 10
socket.TCP_KEEPCNT = 20
socket_options.TCPKeepAliveAdapter()

(Not to confuse anyone, it still doesn't seem to work on Windows!)

Anyone aware of a way to configure this socket behavior in the code without having established a socket? I've avoided delving into requests thus far, and so the only way I have found is the following (REF):

this_socket = socket.fromfd(response.raw.fileno(), socket.AF_INET, socket.SOCK_STREAM)
this_socket.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 10000, 3000))

This appears to manually send the keep alive if anyone is interested.

this_socket.send(b'00', socket.MSG_OOB | socket.MSG_DONTROUTE)

This is a good link for reference on Windows behaviors: https://blogs.technet.microsoft.com/nettracer/2010/06/03/things-that-you-may-want-to-know-about-tcp-keepalives

timothyj85 avatar Jul 07 '17 19:07 timothyj85