From 00ccd6685ff1b9ca1d540dd3f69fc776597e3c4c Mon Sep 17 00:00:00 2001 From: deanlee Date: Sun, 8 Dec 2024 22:46:37 +0800 Subject: [PATCH] enhance ws_send by requeuing failed data for retry --- system/athena/athenad.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/system/athena/athenad.py b/system/athena/athenad.py index 55b9476986f678..c51f2f0ca8e542 100755 --- a/system/athena/athenad.py +++ b/system/athena/athenad.py @@ -733,11 +733,16 @@ def ws_recv(ws: WebSocket, end_event: threading.Event) -> None: def ws_send(ws: WebSocket, end_event: threading.Event) -> None: while not end_event.is_set(): + data = None + queue_source = None try: try: data = send_queue.get_nowait() + queue_source = send_queue except queue.Empty: data = low_priority_send_queue.get(timeout=1) + queue_source = low_priority_send_queue + for i in range(0, len(data), WS_FRAME_SIZE): frame = data[i:i+WS_FRAME_SIZE] last = i + WS_FRAME_SIZE >= len(data) @@ -747,6 +752,11 @@ def ws_send(ws: WebSocket, end_event: threading.Event) -> None: pass except Exception: cloudlog.exception("athenad.ws_send.exception") + if data is not None and queue_source is not None: + try: + queue_source.put_nowait(data) + except Exception: + cloudlog.exception("athenad.ws_send.requeue_failed") end_event.set()