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
+38 -8
View File
@@ -1835,23 +1835,53 @@ THEMEMUSIC_CODE = r"""(function () {
# Utility: Fetch debugger targets
def fetch_targets(host, port):
# Utility: Fetch debugger targets with retry
def fetch_targets(host, port, max_retries=15, base_delay=2):
"""Fetch debugger targets from Steam CEF debugger, with retry logic.
Steam's CEF debugger on port 8080 may not be listening on first run.
Retries with exponential backoff (capped at 10s) up to max_retries times.
Old behavior: called sys.exit(0) on any connection failure (silent exit).
New behavior: retries up to max_retries times, then raises the last error.
"""
import time
last_error = None
for attempt in range(max_retries):
try:
conn = http.client.HTTPConnection(host, port, timeout=5)
conn.request("GET", "/json")
resp = conn.getresponse()
if resp.status != 200:
print(f"Failed to fetch targets: {resp.status} {resp.reason}")
sys.exit(0)
msg = f"Failed to fetch targets: {resp.status} {resp.reason}"
print(msg)
raise Exception(msg)
data = resp.read()
return json.loads(data)
targets = json.loads(data)
except (ConnectionRefusedError, socket.timeout, http.client.CannotSendRequest, http.client.RemoteDisconnected, Exception) as e:
print(f"Error fetching debugger targets: {e}")
sys.exit(0)
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: