fix: handle MySQL mirror connection failure gracefully in v1 prepareDb#1578
Merged
Conversation
V1's prepareDb() crashed with ECONNREFUSED when the MySQL mirror sidecar wasn't ready, causing the entire CADT process to exit. V2's prepareV2Db() already handled this gracefully with a try-catch. This aligns V1 with V2's behavior: log the error and continue with the main SQLite database. The mirror will reconnect on the next sync cycle via safeMirrorDbHandler. Also adds the missing connection.end() call in a finally block to prevent connection leaks on any failure path.
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
prepareDb()crashed withECONNREFUSEDwhen the MySQL mirror sidecar wasn't ready at startup, causing the entire CADT process toprocess.exit(1). This is a race condition in K8s pods where the MySQL sidecar takes ~30 seconds to initialize, but CADT starts immediately.prepareV2Db()already handled this gracefully with a try-catch that logs and continues. This PR aligns V1 with V2's behavior: log the error and continue with the main SQLite database. The mirror reconnects on the next sync cycle viasafeMirrorDbHandler().connection.end()call in afinallyblock to prevent connection leaks on any failure path.Test plan
Note
Medium Risk
Changes startup-time database initialization to swallow MySQL mirror connection/creation failures and always close the transient MySQL connection; misconfiguration could now be masked and leave the mirror uninitialized until later.
Overview
V1
prepareDb()now wraps MySQL mirror database setup in atry/catchso mirror connection/DB-create failures (e.g., sidecar not ready) are logged and do not block main database startup.It also ensures the temporary MySQL connection used to
CREATE DATABASEis always closed via afinallyblock, reducing the chance of connection leaks during startup.Reviewed by Cursor Bugbot for commit c0eb64f. Bugbot is set up for automated code reviews on this repo. Configure here.