fix(database): defer FTS backfill on cold start and enforce single-connection pool#5841
Merged
jamesarich merged 1 commit intoJun 18, 2026
Conversation
Force Room single-connection behavior to avoid KMP BundledSQLiteDriver pool-acquire failures during startup and selected-device database switches. Defer the first real per-device FTS backfill so cold-start reads are not blocked behind a long backfill on the single DB connection. Track and cancel scheduled backfill work when switching databases or closing the manager, skip stale database instances, and swallow non-cancellation backfill failures so closed or stale DB cleanup cannot crash the app. Also serialize the single-connection query coroutine context with limitedParallelism(1) and keep the required coroutine opt-in scoped to the Room builder configuration.
jamesarich
approved these changes
Jun 18, 2026
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.
Overview
This addresses an Android database startup failure where BLE could connect but DB-backed state like NodeDB, config, and channels would not reliably finish loading.
The fix explicitly enables Room's single-connection mode on Android, limits query concurrency before work enters Room's acquire path, and defers the first per-device FTS backfill so startup reads are not competing with search-index maintenance work.
Key Changes
Validation
Recent debug logs no longer show the previous Room failure signature: no reader-acquisition timeouts, no SQLExceptions, no ConnectionPoolImpl dumps, no permits=0 pool state, no fatal exception, and no ANR.
The latest runs successfully reached BLE session ready, mesh handshake, MyNodeInfo, local metadata, config load, NodeDB completion, and history replay.
Notes
Related: #5828
This is an Android release reliability mitigation for Room 3.0.x KMP + BundledSQLiteDriver, not a statement that the app must stay single-connection forever.
Multi-reader Android Room can be revisited after a Room upgrade or an upstream pool fix, with stress coverage for DB switching and cancelled Room-backed flows.
Breaking Changes / Migration Notes
None. No schema migration, destructive cleanup, or user-data reset is introduced.
Update: I've been running this on multiple devices for ~8 hours without reproducing the original failure.