Skip to content

fix(database): make withDb retry logic resilient to varying close messages#5474

Merged
jamesarich merged 1 commit into
mainfrom
jamesarich/fix-flaky-database-manager-retry-test
May 18, 2026
Merged

fix(database): make withDb retry logic resilient to varying close messages#5474
jamesarich merged 1 commit into
mainfrom
jamesarich/fix-flaky-database-manager-retry-test

Conversation

@jamesarich

Copy link
Copy Markdown
Collaborator

Summary

Fixes the flaky DatabaseManagerWithDbRetryTest::withDb retries against current database when previous pool closes during switch test that keeps flapping on CI.

Root Cause

The withDb retry mechanism only triggered on the exact string "Connection pool is closed", but Room KMP with the bundled SQLite driver can produce different error messages when a database is closed (e.g., "database is closed", "Cannot use connection, it is closed"). When the message didn't match, the retry was skipped and the test failed.

Changes

Replaces the brittle single-message check with a more robust approach:

  1. Reference comparison (retryDb !== db) — confirms a DB switch actually occurred before retrying
  2. Cause-chain scan — inspects the full exception chain for "closed" + a DB-related term (pool, database, connection, sqlite)
  3. Suppressed exception preservation — if the retry also fails, the original exception is attached as suppressed for debuggability

Testing

  • ./gradlew :core:database:testAndroidHostTest :core:database:allTests
  • ./gradlew :core:database:spotlessCheck :core:database:detekt

…sages

The retry in withDb previously only triggered on the exact message
"Connection pool is closed". Room KMP with bundled SQLite can produce
different messages (e.g. "database is closed", "Cannot use connection,
it is closed") depending on driver/platform, causing the retry test to
flap on CI.

Replace the brittle string check with:
- A reference comparison (retryDb !== db) to confirm a DB switch occurred
- A cause-chain scan for any message containing "closed" plus a DB term
- Suppressed-exception preservation on retry failure for debuggability

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added the bugfix PR tag label May 18, 2026
@jamesarich jamesarich added this pull request to the merge queue May 18, 2026
Merged via the queue into main with commit 057d5bb May 18, 2026
14 checks passed
@jamesarich jamesarich deleted the jamesarich/fix-flaky-database-manager-retry-test branch May 18, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix PR tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant