Add try-catch in _replicate() to log exceptions instead of crashing silently#2501
Closed
Add try-catch in _replicate() to log exceptions instead of crashing silently#2501
Conversation
…ilently The _replicate() thread had no exception handling, so any STHROW (from SQLITE_BUSY_SNAPSHOT, hash mismatch, commit count mismatch, etc.) would kill the thread silently. The network thread would keep queuing messages into the unbounded _replicateQueue, causing the follower to fall further behind with no recovery and no diagnostic logging. This wraps the message processing in a try-catch that logs SALERT with full diagnostic context (message type, error, commit count, peer name), rolls back any in-progress transaction, and exits the thread cleanly. This is a diagnostic change to confirm whether uncaught exceptions in the replicate thread are the root cause of follower replication stalls (as seen with virt1.sjc falling ~390K commits behind). Co-authored-by: Robert Chen <robertjchen@users.noreply.github.com>
Contributor
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
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.
Explanation of Change
The
_replicate()thread inSQLiteNode.cpphad no exception handling. AnySTHROW(fromSQLITE_BUSY_SNAPSHOT, hash mismatch, commit count mismatch, etc.) would kill the thread silently. The network thread would continue queuing messages into the unbounded_replicateQueue, but nothing would process them — causing the follower to fall further behind with no recovery and no diagnostic logging.This wraps the message processing block in a try-catch that:
SALERTwith full diagnostic context (message type, error, commit count, peer name)returnThis is a diagnostic-only change to confirm whether uncaught exceptions in the replicate thread are the root cause of follower replication stalls (as seen with
virt1.sjcfalling ~390K commits behind).The behavior change: instead of the thread crashing silently from an unhandled exception, it now logs the cause at SALERT level and exits gracefully. The thread still exits — no recovery is attempted yet. Future work can add recovery (e.g., transitioning to SEARCHING state) once we confirm this is the root cause.
Fixed Issues
$ https://github.com/Expensify/Expensify/issues/597997
Tests
catch (const SException& e)pattern used throughoutSQLiteNode.cpp(lines 1503, 1578, 1642, 1714, 1750)Web QA
No web QA needed — this is a Bedrock infrastructure change that adds logging to the replication thread. The functional behavior (thread exits on error) is unchanged; the only difference is that the error is now logged via SALERT before exiting instead of crashing silently.
Mobile QA
No mobile QA needed.