This commit is contained in:
david committed 2026-09-08 02:12:15 -03:00
1 parent bdd7d1f57c
commit 64af28f820
1 file changed
+4 -1
+4 -1
View File
@@ -110,8 +110,9 @@ _main_ws = None # kept open across messages instead of reconnecting every time
async def call_main(payload: str) -> tuple[bool, str]:
global _main_ws
for attempt in range(2): # retry once with a fresh connection if the cached one turned out dead
try:
if _main_ws is None or _main_ws.closed:
if _main_ws is None:
_main_ws = await websockets.connect(MAIN_URI, open_timeout=None, ping_timeout=None)
await _main_ws.send(payload)
raw = await _main_ws.recv()
@@ -124,6 +125,8 @@ async def call_main(payload: str) -> tuple[bool, str]:
return False, f"[{now_str()}] websocket closed cleanly (no reply)"
except Exception as e:
_main_ws = None
if attempt == 0:
continue # one retry with a fresh connection before giving up
return False, f"[{now_str()}] websocket error: {e}"
async def handle_error(error_msg: str, notify_channel=None, notify_user=None):