Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

athenad: enhance ws_send by requeuing failed data to prevent loss after reconnection #34184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions system/athena/athenad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()


Expand Down
Loading