mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
fix: improve PKI message routing and resolve database migration racecondition (#4996)
This commit is contained in:
parent
d0e3b682ab
commit
b3be9e2c38
14 changed files with 277 additions and 37 deletions
|
|
@ -125,16 +125,21 @@ open class DatabaseManager(
|
|||
// Build/open Room DB off the main thread
|
||||
val db = withContext(dispatchers.io) { getOrOpenDatabase(dbName) }
|
||||
|
||||
if (previousDbName != null && previousDbName != dbName) {
|
||||
closeCachedDatabase(previousDbName)
|
||||
}
|
||||
|
||||
// Emit the new DB BEFORE closing the old one. flatMapLatest collectors on
|
||||
// currentDb will cancel their in-flight queries on the previous database once
|
||||
// the new value is emitted. Closing the old pool first would race with those
|
||||
// collectors, causing "Connection pool is closed" crashes.
|
||||
_currentDb.value = db
|
||||
_currentAddress.value = address
|
||||
markLastUsed(dbName)
|
||||
// Also mark the previous DB as used "just now" so LRU has an accurate, recent timestamp
|
||||
previousDbName?.let { markLastUsed(it) }
|
||||
|
||||
// Now safe to close the previous DB — collectors have switched to the new instance.
|
||||
if (previousDbName != null && previousDbName != dbName) {
|
||||
closeCachedDatabase(previousDbName)
|
||||
}
|
||||
|
||||
// Defer LRU eviction so switch is not blocked by filesystem work
|
||||
managerScope.launch(dispatchers.io) { enforceCacheLimit(activeDbName = dbName) }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue