fix(database): make withDb retry logic resilient to varying close messages#5474
Merged
jamesarich merged 1 commit intoMay 18, 2026
Merged
Conversation
…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>
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
Fixes the flaky
DatabaseManagerWithDbRetryTest::withDb retries against current database when previous pool closes during switchtest that keeps flapping on CI.Root Cause
The
withDbretry 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:
retryDb !== db) — confirms a DB switch actually occurred before retryingpool,database,connection,sqlite)Testing
./gradlew :core:database:testAndroidHostTest :core:database:allTests✅./gradlew :core:database:spotlessCheck :core:database:detekt✅