Skip to content

fix: handle MySQL mirror connection failure gracefully in v1 prepareDb#1578

Merged
TheLastCicada merged 1 commit into
v2-rc2from
fix/v1-mirror-db-startup-crash
Apr 10, 2026
Merged

fix: handle MySQL mirror connection failure gracefully in v1 prepareDb#1578
TheLastCicada merged 1 commit into
v2-rc2from
fix/v1-mirror-db-startup-crash

Conversation

@TheLastCicada

@TheLastCicada TheLastCicada commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • V1's prepareDb() crashed with ECONNREFUSED when the MySQL mirror sidecar wasn't ready at startup, causing the entire CADT process to process.exit(1). This is a race condition in K8s pods where the MySQL sidecar takes ~30 seconds to initialize, but CADT starts immediately.
  • V2's 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 via safeMirrorDbHandler().
  • Also adds a missing connection.end() call in a finally block to prevent connection leaks on any failure path.

Test plan

  • Deploy to testneta observer namespace and verify CADT starts without crash loops when MySQL sidecar is still initializing
  • Verify mirror DB connects and syncs once MySQL becomes available
  • Verify normal startup behavior is unchanged when MySQL is already running

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 a try/catch so 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 DATABASE is always closed via a finally block, 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.

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.
@TheLastCicada TheLastCicada changed the base branch from develop to v2-rc2 April 10, 2026 21:14
@TheLastCicada TheLastCicada merged commit a94ef07 into v2-rc2 Apr 10, 2026
26 checks passed
@TheLastCicada TheLastCicada deleted the fix/v1-mirror-db-startup-crash branch April 10, 2026 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant