From 881b23eb756f17671418148e286d74090a60a721 Mon Sep 17 00:00:00 2001 From: ayushsingh82 Date: Sat, 8 Aug 2026 08:58:52 +0530 Subject: [PATCH] fix(backend): break outer loop on client write failure for accesses/TPS Motivation: In client_write_task, a failed send_message() for the accesses_buf or tps_buf messages only broke the inner `for` loop over the buffered items, not the outer task loop. This is inconsistent with the events_buf send right above it, which correctly breaks the outer loop on failure. A send failure here means the client is gone (write error on the WebSocket, e.g. broken pipe after disconnect). Once that happens, the task should stop - but with the inner break, it fell through to the next iteration of the outer loop and kept trying (and failing) to serve the same dead connection indefinitely instead of exiting, unlike every other failure path in this function. Modifications: Label the outer loop and change the two nested breaks to `break 'outer'` so a write failure on any buffer (events, accesses, or TPS) terminates the task the same way. Result: client_write_task now exits promptly on any write failure, regardless of which buffer triggered it, matching its behavior for the other error paths in the same function (broadcast receiver errors, events send failures). --- backend/src/lib/server.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/lib/server.rs b/backend/src/lib/server.rs index a3724bb..48590ff 100644 --- a/backend/src/lib/server.rs +++ b/backend/src/lib/server.rs @@ -131,7 +131,7 @@ async fn client_write_task( let mut accesses_buf: Vec = Vec::new(); let mut tps_buf: Vec = Vec::new(); - loop { + 'outer: loop { // Wait for first event match event_broadcast_receiver.recv().await { Ok(event) => process_event(event, &filter, &mut events_buf, &mut accesses_buf, &mut tps_buf), @@ -160,7 +160,7 @@ async fn client_write_task( let server_msg = ServerMessage::TopAccesses(accesses); if let Err(e) = send_message(&mut ws_sender, server_msg).await { error!("Failed to send accesses to {}: {}", addr, e); - break; + break 'outer; } } } @@ -170,7 +170,7 @@ async fn client_write_task( let server_msg = ServerMessage::TPS(tps); if let Err(e) = send_message(&mut ws_sender, server_msg).await { error!("Failed to send TPS to {}: {}", addr, e); - break; + break 'outer; } } }