fix: retry WebSocket connection on first run instead of silent exit

fetch_targets() called sys.exit(0) on ConnectionRefusedError. Steam's CEF
debugger on port 8080 is not always ready on first run, so the scanner exited
silently and added no shortcuts (issue #895, first-run half).

Replace with retry + exponential backoff (15 attempts, 2s base, 10s cap),
print progress so the retry is visible, and raise the last error instead of
exiting silently.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
superness
2026-06-09 20:41:10 -04:00
parent c0f0fcc68a
commit bb73939339
+49 -19
View File
@@ -1835,29 +1835,59 @@ THEMEMUSIC_CODE = r"""(function () {
# Utility: Fetch debugger targets # Utility: Fetch debugger targets with retry
def fetch_targets(host, port): def fetch_targets(host, port, max_retries=15, base_delay=2):
try: """Fetch debugger targets from Steam CEF debugger, with retry logic.
conn = http.client.HTTPConnection(host, port, timeout=5)
conn.request("GET", "/json")
resp = conn.getresponse()
if resp.status != 200: Steam's CEF debugger on port 8080 may not be listening on first run.
print(f"Failed to fetch targets: {resp.status} {resp.reason}") Retries with exponential backoff (capped at 10s) up to max_retries times.
sys.exit(0)
data = resp.read() Old behavior: called sys.exit(0) on any connection failure (silent exit).
return json.loads(data) New behavior: retries up to max_retries times, then raises the last error.
"""
import time
except (ConnectionRefusedError, socket.timeout, http.client.CannotSendRequest, http.client.RemoteDisconnected, Exception) as e: last_error = None
print(f"Error fetching debugger targets: {e}") for attempt in range(max_retries):
sys.exit(0)
finally:
try: try:
conn.close() conn = http.client.HTTPConnection(host, port, timeout=5)
except: conn.request("GET", "/json")
pass resp = conn.getresponse()
if resp.status != 200:
msg = f"Failed to fetch targets: {resp.status} {resp.reason}"
print(msg)
raise Exception(msg)
data = resp.read()
targets = json.loads(data)
if attempt > 0:
print(f"Connected to Steam debugger on attempt {attempt + 1}/{max_retries}")
return targets
except (ConnectionRefusedError, socket.timeout,
http.client.CannotSendRequest, http.client.RemoteDisconnected,
OSError, Exception) as e:
last_error = e
if attempt < max_retries - 1:
delay = min(base_delay * (attempt + 1), 10)
print(f"Steam debugger not ready (attempt {attempt + 1}/{max_retries}), "
f"retrying in {delay}s... ({e})")
time.sleep(delay)
else:
print(f"ERROR: Could not connect to Steam debugger at {host}:{port} "
f"after {max_retries} attempts.")
print(f"Make sure Steam is running with these launch options:")
print(f" -dev -cef-enable-debugging -cef-single-process")
raise last_error
finally:
try:
conn.close()
except:
pass
# Find websocket debugger URL for the target title # Find websocket debugger URL for the target title
def get_ws_url_by_title(host, port, title): def get_ws_url_by_title(host, port, title):