fix(backend): break outer loop on client write failure for accesses/TPS - #116
Open
ayushsingh82 wants to merge 1 commit into
Open
fix(backend): break outer loop on client write failure for accesses/TPS#116ayushsingh82 wants to merge 1 commit into
ayushsingh82 wants to merge 1 commit into
Conversation
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).
ayushsingh82
requested review from
Camillebzd,
Im-Madhur-Gupta,
iamvukasin,
marcuspang and
mijovic
as code owners
August 8, 2026 03:29
|
@ayushsingh82 is attempting to deploy a commit to the MF Flagship Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
client_write_taskinbackend/src/lib/server.rssends three kinds of buffered messages to a WebSocket client each iteration:events_buf,accesses_buf, andtps_buf. Whensend_message()fails forevents_buf, the code correctlybreaks the outerloop, terminating the task for that (now-dead) connection.But for
accesses_bufandtps_buf, the send happens inside aforloop over the buffered items, and thebreakon failure only exits that innerforloop — not the outer task loop:A
send_messagefailure here means the client's WebSocket write is broken (e.g. disconnected). Once that happens, the task should exit — same intent as theevents_bufpath right above it — but instead it falls through and keeps looping, repeatedly trying (and failing) to serve a dead connection instead of terminating.Changes
loopas'outerand change the two nestedbreaks (in theaccesses_bufandtps_bufsend loops) tobreak 'outer, so a write failure on any buffer terminates the task consistently.breaks elsewhere in the function (broadcast receiver error, events send failure) are unaffected since they weren't nested in aforloop to begin with.Test plan
breakinside aforinside alooponly exits thefor) and confirmed the labeled-loop fix resolves it.cargo fmt --checkpasses on the crate.cargo check/cargo clippy/cargo test— could not run locally on macOS;monad-event-ring's build script requirescmakeand Linuxhugetlbfsheaders not available in this environment (same constraint noted in fix(backend): prevent panic when txn_idx exceeds fixed buffer size #115). Deferred to CI.Greptile Summary
This PR corrects WebSocket writer termination after TopAccesses or TPS delivery fails.
Confidence Score: 5/5
The PR appears safe to merge because the changed breaks now terminate work for a connection whose WebSocket writer has already failed.
The labeled breaks correct the nested-loop control flow without changing successful delivery behavior or introducing a reachable lifecycle failure.
Important Files Changed
Reviews (1): Last reviewed commit: "fix(backend): break outer loop on client..." | Re-trigger Greptile