From f0818e1eae8cc8f79b4840292676b7aad8a91e7a Mon Sep 17 00:00:00 2001 From: scottf007 Date: Sat, 28 Mar 2026 01:50:59 +1100 Subject: [PATCH] Add socket timeout to is_port_in_use() to fix ~280s startup delay on WSL2 (#2077) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- koboldcpp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/koboldcpp.py b/koboldcpp.py index 34fe0398b..96fe20ea3 100755 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -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