Title: socket.connect() slow to time out on Windows
Type: performance Stage: test needed
Components: Windows Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2020-07-15 21:21 by steve.dower, last changed 2020-07-15 21:21 by steve.dower.

Messages (1)
msg373725 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2020-07-15 21:21
When connecting to localhost, socket.connect() takes two seconds on Windows (the default) to time out, but on Linux (including WSL) it times out immediately.

Test code (assuming port 9999 has no listener):
>>> import socket
>>> socket.socket().connect(('localhost', 9999))

For a remote host, the timeout is approx 10s on Windows and 20s on WSL (I didn't test on a native Linux box).

I'm told the correct fix is to specify TCP_INITIAL_RTO_NO_SYN_RETRANSMISSIONS [1] when connecting to localhost.
Date User Action Args
2020-07-15 21:21:16steve.dowercreate