Add socket timeout to is_port_in_use() to fix ~280s startup delay on WSL2 (#2077)

On WSL2 with networkingMode=mirrored, connect_ex() to non-listening ports
gets black-holed through the Windows host networking stack instead of
returning ECONNREFUSED. Without a timeout, TCP SYN retransmits with
exponential backoff (1+2+4+8+16+32+64 ≈ 127s per port), causing Router
Mode's port scan of 15001-15010 to stall for ~280 seconds on startup.

Adding a 1-second timeout makes connect_ex() fail fast, reducing startup
from ~303s to ~23s on affected systems.

Tested on WSL2 Ubuntu 24.04 with mirrored networking, KoboldCpp v1.110,
RTX 3090 Ti, Qwen3.5-27B Q4_K_M.
This commit is contained in:
scottf007 2026-03-28 01:50:59 +11:00 committed by GitHub
parent a03998bed6
commit f0818e1eae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2898,6 +2898,7 @@ def websearch(query):
def is_port_in_use(portNum):
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(1)
return s.connect_ex(('localhost', portNum)) == 0
except Exception:
return True