Skip to content

fix(database): defer FTS backfill on cold start and enforce single-connection pool#5841

Merged
jamesarich merged 1 commit into
meshtastic:mainfrom
jeremiah-k:bugfix/room-single-connection-pool
Jun 18, 2026
Merged

fix(database): defer FTS backfill on cold start and enforce single-connection pool#5841
jamesarich merged 1 commit into
meshtastic:mainfrom
jeremiah-k:bugfix/room-single-connection-pool

Conversation

@jeremiah-k

@jeremiah-k jeremiah-k commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

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

  • Explicitly force Android production Room into single-connection mode.
  • Limit the single-connection query dispatcher to one lane before work enters Room's acquire path.
  • Defer the first real per-device FTS backfill on cold startup.
  • Cancel stale delayed backfill work when switching databases or closing the manager.
  • Skip delayed backfill work if the database is no longer active.
  • Preserve startup ordering: selected address → switch active DB → load cached NodeDB → connect radio.

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.

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 jamesarich added this pull request to the merge queue Jun 18, 2026
Merged via the queue into meshtastic:main with commit e94f2ee Jun 18, 2026
20 checks passed
@jeremiah-k jeremiah-k deleted the bugfix/room-single-connection-pool branch June 18, 2026 11:45
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.

2 participants