Status Update
Comments
ae...@gmail.com <ae...@gmail.com> #2
Branch: androidx-master-dev
commit b90079595f33f58fece04026a97faa0d243acdb1
Author: Yuichi Araki <yaraki@google.com>
Date: Wed Sep 18 16:55:49 2019
Change the way to detect mismatch between POJO and query
This fixes cursor mismatch warnings with expandProjection.
Bug: 140759491
Test: QueryMethodProcessorTest
Change-Id: I7659002e5e0d1ef60fc1af2a625c0c36da0664d8
M room/compiler/src/main/kotlin/androidx/room/processor/QueryMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
M room/compiler/src/main/kotlin/androidx/room/solver/query/result/PojoRowAdapter.kt
M room/compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
M room/compiler/src/test/kotlin/androidx/room/testing/TestProcessor.kt
el...@google.com <el...@google.com> #3
ae...@gmail.com <ae...@gmail.com> #4
Branch: androidx-master-dev
commit bdde5a1a970ddc9007b28de4aa29d60ffa588f08
Author: Yigit Boyar <yboyar@google.com>
Date: Thu Apr 16 16:47:05 2020
Re-factor how errors are dismissed when query is re-written
This CL changes how we handle errors/warnings if query is
re-written.
There was a bug in expandProjection where we would report warnings
for things that Room already fixes automatically (
The solution to that problem (I7659002e5e0d1ef60fc1af2a625c0c36da0664d8)
solved it by deferring validating of columns until after re-write
decision is made. Unfortunately, this required changing PojoRowAdapter
to have a dummy mapping until it is validating, make it hard to use
as it does have a non-null mapping which is not useful.
This CL partially reverts that change and instead rely on the log
deferring logic we have in Context. This way, we don't need to break
the stability of PojoRowAdapter while still having the ability to
drop warnings that room fixes. This will also play nicer when we
have different query re-writing options that can use more information
about the query results.
Bug: 153387066
Bug: 140759491
Test: existing tests pass
Change-Id: I2ec967c763d33d7a3ff02c1a13c6953b460d1e5f
M room/compiler/src/main/kotlin/androidx/room/log/RLog.kt
M room/compiler/src/main/kotlin/androidx/room/processor/QueryMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
M room/compiler/src/main/kotlin/androidx/room/solver/query/result/PojoRowAdapter.kt
ae...@gmail.com <ae...@gmail.com> #6
Hi. Please merge the pull request. This is big problem!
ae...@gmail.com <ae...@gmail.com> #7
Hi. Is there any updates on this problem?
ae...@gmail.com <ae...@gmail.com> #8
Hi, I updated my version to alpha12 but still have these crashes. Please release a fix asap.
ae...@gmail.com <ae...@gmail.com> #9
Will there be fixes released this Wednesday?
da...@google.com <da...@google.com> #10
Hey, there is no release on Wednesday (holiday in the USA)
We haven't found the root cause of this exception, it happens when SQLite can't commit the transaction because some other connection has a lock, we need more information, a sample project that reproduces the issue preferably, or more details on how the database is being used (is it from multiple process? is there heavy concurrency?).
You can also increase the time SQLite will wait before it error with 'database locked' by executing PRAGMA busy_timeout = <time in ms>
, the current default is 3000
ae...@gmail.com <ae...@gmail.com> #11
Thank you for you response.
- Isn't these pull request addressed this issue?
1.1
https://android-review.googlesource.com/c/platform/frameworks/support/+/3408679 1.2https://android-review.googlesource.com/c/platform/frameworks/support/+/3114928 - According to RoomDB documentation about
withTransaction
: "Room will only perform at most one transaction at a time, additional transactions are queued and executed on a first come, first serve order." So the transaction should just wait for other transaction to complete and not throw exception instead. Isn't it?
ae...@gmail.com <ae...@gmail.com> #12
I tried to use this code and still getting the same error from users. (deferredTransaction
instead of immediateTransaction
)
private val dbMutex = Mutex()
suspend fun <R> MyDatabse.workaroundWithTransaction(block: suspend TransactionScope<R>.() -> R) {
dbMutex.withLock {
useWriterConnection {
it.deferredTransaction(block)
}
// TODO: Fix https://issuetracker.google.com/issues/340606803#comment2
// Manually triggers invalidation
invalidationTracker.refreshAsync()
}
}
ae...@gmail.com <ae...@gmail.com> #13
Moreover now I am also think that @Update
function caused particularly this crash. I will monitor the situation to this if this 1 crash or it will be more with the same reason.
ae...@gmail.com <ae...@gmail.com> #14
After checking I can confirm that this crash happens as many as before.
ae...@gmail.com <ae...@gmail.com> #15
The crash occurs when the user adds a new record to the database from the interface, and the crash occurs when the application starts in the first 1-2 seconds. The crash also occurs when receiving records from the database.
This is just a disaster, please fix it.
da...@google.com <da...@google.com> #16
Sorry, I don't believe those two pull request address the issue you are seeing.
If you can reliably reproduce can you please send us a sample project?
Besides adding a Mutex
did you also try increasing the busy timeout with the PRAGMA? Can you please share more details how the database is being used? Are you starting a transaction and performing many @Update
? Is the coroutine where the transaction occurring getting canceled and restarted? The theory here is maybe cancelation is not recycling the connection correctly and there is a lingering transaction that prevents other ones from finishing.
Can you also try and configure Room with the AndroidSQLiteDriver()
? This would help us know if the issue is specific to the BundledSQLiteDriver
or not.
I have yet to reproduce to issue, I've tried creating 'stress tests' like the following:
@Test
fun daoUsagesInTransaction() = runTest {
List(100) {
launch(Dispatchers.IO) {
db.useWriterConnection { transactor ->
transactor.immediateTransaction {
val e = SampleEntity(1)
db.dao().insert(e)
db.dao().update(e)
db.dao().delete(e)
}
}
db.invalidationTracker.refreshAsync()
}
}.joinAll()
}
ae...@gmail.com <ae...@gmail.com> #17
Hi. Thank you for your response.
- My app have BroadcastReceivers and WorkManagers that reads and writes in the same database that the app does. Could it be the problem? But! The logic didn't change since I moved from android only to shared module. On android it was working just fine.
- Currently I didn't succeed in reproducing it by myself.
- Have I tried to reproduce it by stress tests? Yes, but I haven't get the crash.
- "did you also try increasing the busy timeout with the PRAGMA?" - No, I didn't. I thought that it may be command just for my local device for testing. I google it see that I could execute it in query format when setting up Room. But I don't have so match long data read of write. I and thinking about it now.
- "Can you please share more details how the database is being used?" - As example of my app: task tracking app. The user enters tasks via UI, tasks sync with other user device, task can show local alerts notification to remind.
- "Are you starting a transaction and performing many @Update?" - It could do non-users operations when:
- Starts the app the notes are being sent or received (the App scope).
- Starts the app the other data updated via WorkManager (the WorkManager scope).
- Receives alert notification and BroadcastReceivers plans new notification and updates info about it in database (BroadcastReceiver scope).
- "The theory here is maybe cancelation is not recycling the connection correctly and there is a lingering transaction that prevents other ones from finishing." - I am now trying to ger rid of WorkManagers because I heard that they may start in another process then the app. I will see if it would help.
- "Can you also try and configure Room with the AndroidSQLiteDriver()?" - I tried to implement it but I don't understand how. My database placed in common module. The RoomDB generates implementation for each platform. How could I make my android implementation so I could use
AndroidSQLiteDriver()
?
da...@google.com <da...@google.com> #18
1 & 6 - WorkManager workers and broadcast receiver interacting with the same Room database is fine. I was more curious on the operations being done, but it does seem to be write operations in transactions.
4 - You can configure the timeout in Room's onOpen
addCallback()
onOpen
just do: conenction.execSQL("PRAGMA busy_timeout = <time in ms>")
7 - You should check your AndroidManifest.xml
, WorkManager could run in another process, but only if configured to do so, check if your app has multiple processes by checking the manifest and looking for android:process=
8 - Because AndroidSQLiteDriver
is an Android only API you need to create an actual / expect function that return a SQLiteDriver
along with the necessary Kotlin multiplatform source set configuration so that for Android it'll return AndroidSQLiteDriver
while for other platforms I'll return BundledSQLiteDriver
and you pipe that to `setDriver().
ae...@gmail.com <ae...@gmail.com> #19
Hi. I have updated my app replaced BundledSQLiteDriver
with AndroidSQLiteDriver
as you suggested.
For now I don't see SQLException: Error code: 5, message: database is locked
anymore but I see the new error java.lang.IllegalStateException: Cannot perform this operation because there is no current transaction.
Here is the stack trace.
Fatal Exception: java.lang.IllegalStateException: Cannot perform this operation because there is no current transaction.
at android.database.sqlite.SQLiteSession.throwIfNoTransaction(SQLiteSession.java:917)
at android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:400)
at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:588)
at androidx.room.coroutines.AndroidSQLiteDriverPooledConnection.transaction(AndroidSQLiteDriverConnectionPool.android.kt:94)
at androidx.room.coroutines.AndroidSQLiteDriverPooledConnection.access$transaction(AndroidSQLiteDriverPooledConnection.java:53)
at androidx.room.coroutines.AndroidSQLiteDriverPooledConnection$transaction$1.invokeSuspend(AndroidSQLiteDriverConnectionPool.android.kt:12)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:98)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.java:113)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:586)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:820)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:717)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:704)
el...@google.com <el...@google.com>
ae...@gmail.com <ae...@gmail.com> #20
Hi. Happy New Year!
After week with AndroidSQLiteDriver
I see no SQLException: Error code: 5, message: database is locked
but see java.lang.IllegalStateException: Cannot perform this operation because there is no current transaction.
.
So I think your theory may be right that this is something with "Coroutines and RoomDB".
ae...@gmail.com <ae...@gmail.com> #21
Hi. This is still a problem. Should I create new issue about java.lang.IllegalStateException: Cannot perform this operation because there is no current transaction.
or it is going to be fixed in scope of this issue?
This issue is still blocker for my app and there is already 46 days passed since I reported it.
da...@google.com <da...@google.com> #22
Hi - Sorry for the delayed response.
I think you are indeed hitting a different issue with the AndroidSQLiteDriver
, specifically around the
But I am worried that we still have not found the root cause of your original issue with the BundledSQLiteDriver
and the database is locked
, if you could somehow create a sample app (I know it can be hard) that would help us a lot.
I also want to mention a 3rd option for Android and that is not using a SQLiteDriver
with Room which in turn will cause it to default to using SupportSQLite
the underlying SQLite APIs before Room was converted to KMP.
ae...@gmail.com <ae...@gmail.com> #23
Hi. Thank you for your response. For now I am not succeed in reproduce the issue with the BundledSQLiteDriver
and the database is locked
. But I will try more.
Speaking of "not using a SQLiteDriver" - am I understood right that I just need to delete .setDriver()
method?
da...@google.com <da...@google.com> #24
Thats right, not calling setDriver
will make Room work in compatibility mode and will use the FrameworkSQLiteOpenHelper
and its APIs and will keep the 'before KMP coroutines' behavior.
ae...@gmail.com <ae...@gmail.com> #25
So. I removed setDriver
method. The builder is still in common module. Now the error IllegalStateException: Cannot perform this operation because there is no current transaction
happens every time when app trying to make database operation using this code
private val dbMutex = Mutex()
suspend fun <R> MyDatabse.workaroundWithTransaction(block: suspend TransactionScope<R>.() -> R) {
dbMutex.withLock {
useWriterConnection {
it.deferredTransaction(block)
}
// TODO: Fix https://issuetracker.google.com/issues/340606803#comment2
// Manually triggers invalidation
invalidationTracker.refreshAsync()
}
}
The stack trace:
java.lang.IllegalStateException: Cannot perform this operation because there is no current transaction.
at android.database.sqlite.SQLiteSession.throwIfNoTransaction(SQLiteSession.java:1021)
at android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:419)
at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:833)
at androidx.sqlite.db.framework.FrameworkSQLiteDatabase.endTransaction(FrameworkSQLiteDatabase.android.kt:100)
at androidx.room.driver.SupportSQLitePooledConnection.transaction(SupportSQLiteConnectionPool.android.kt:90)
at androidx.room.driver.SupportSQLitePooledConnection.access$transaction(SupportSQLiteConnectionPool.android.kt:51)
at androidx.room.driver.SupportSQLitePooledConnection$transaction$1.invokeSuspend(Unknown Source:15)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:98)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:113)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:820)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:717)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:704)
Note: there was AndroidSQLiteDriverPooledConnection
now it is SupportSQLitePooledConnection
in stack trace.
ae...@gmail.com <ae...@gmail.com> #26
Also, users report that when using the Android driver, sometimes the database does not return a response from an SQL query where it should have returned it.
The example of such request
@Query("""SELECT * from "${Holder.TABLE_HOLDER}" WHERE "${Holder.COLUMN_HOLDER_ID}" LIKE :holderId""")
fun getHolderById(holderId: String): Flow<Holder?>
ae...@gmail.com <ae...@gmail.com> #27
I found the way to reproduce it!
First you launch workaroundWithTransaction
method, then getHolderById
method. The result: getHolderById
stops returning result.
This error is ever worse than before because it is reproduceable in almost 100% cases!
I have to return to BundledSQLiteDriver
da...@google.com <da...@google.com> #28
Can you provide more details on the repro case? Is it possible to create a sample repro? Or maybe a test? Can you please show us some code?
Are you starting a transaction and in the transaction you are also collecting the Flow?
db.workaroundWithTransaction {
db.dao.getHolderById(...).collect {
}
}
This is not a valid usage of Flow
because you are essentially starting a transaction that will never end and that might explain the database locked
exception you are seeing.
Here another test I have created based on your description but it works fine for me on all drivers:
@Test
fun check() = runTest {
async(Dispatchers.IO) {
// Insert 100 items in a deferred transaction and notifying invalidation tracker
repeat(100) { id ->
db.useWriterConnection {
it.deferredTransaction {
db.dao().insert(SampleEntity(id.toLong()))
}
}
db.invalidationTracker.refreshAsync()
}
}
async(Dispatchers.IO) {
// Collect list of inserted items until list is of size 100, meaning
// all 100 items where inserted and a result with a list of them was received
db.dao().getItemListFlow().collect {
if (it.size == 100) {
cancel()
}
}
}
}
ae...@gmail.com <ae...@gmail.com> #29
Hi. The order of reproducing:
- call
db.dao().getHolderById("some_id").first()
- will return a result - call
db.useWriterConnection {...}
- to make any change in db - call
db.dao().getHolderById("some_id").first()
- no longer returns a result
Only restarting the app will make db.dao().getHolderById("some_id").first()
work again.
For now I can't create a simple repo, maybe later.
ba...@gmail.com <ba...@gmail.com> #30
I don't have a minimal repro case, but I am facing this issue in my project (
I have been using AndroidSQLiteDriver
in production and never had a database locked crash. Many months ago I briefly deployed BundledSQLiteDriver
but reverted it because of this crash
This weekend I wanted to use window functions on Android so I switched to BundledSQLiteDriver
again. It did not crash on my Pixel 9 Pro during development so I thought the issue was fixed. Then I deployed my changes and am getting tons of crashes again
I then tested on a CAT S22. This thing is a potato and I get database locked crashes easily.
I commented out my transactor.withTransaction
calls so the only transactions are generated by Room and it still crashes
When I use PRAGMA busy_timeout
to increase the timeout then the database just deadlocks instead of crashing
ba...@gmail.com <ba...@gmail.com> #31
Just to add more details:
I can comment out my @RawQuery
, useWriterConnection
, and useReaderConnection
calls, and I still get database locked crashes using only generated @Query
, @Insert
, @Update
, and @Delete
functions. The app runs in a single process
Switching from BundledSQLiteDriver
back to AndroidSQLiteDriver
fixes the issue completely
On my CAT S22 the app crashes on first launch after a clean install 100% of the time. The app will start after relaunching but it will then crash frequently during synchronization
ae...@gmail.com <ae...@gmail.com> #32
Hi. Is there any updates? I believe it is should be P1 issue.
ba...@gmail.com <ba...@gmail.com> #33
My guess, without looking at any of the library code, is that transactions are not being queued with the BundledSQLiteDriver. I have firebase crashes from 20+ different database functions at this point. My pixel 9 pro is probably servicing requests fast enough to not crash, the CAT S22 not so much.
da...@google.com <da...@google.com> #34
I'll grab an old Nexus 5 I have around that is pretty potato to see if I can repro this.
Room has a connection pool manager and it has 4 reader connections and one writer, it uses
ba...@gmail.com <ba...@gmail.com> #35
I became aware of room's connection strategy when I learned that reading data with Room flows acquired a transaction, which was a surprising source of performance problems at my day job 🙃
I thought using AndroidSQLiteDriver
was analogous to not specifying a driver at all, and would use the connection/transaction strategy you mentioned. Based on my observations I assumed this was related to the problem with the BundledSQLiteDriver
- transactions are happening on multiple connections rather than queuing them on one connection? I'm just speculating and could also be mistaken about how this works under the hood.
If you're trying to repro by running my app but aren't having any luck let me know, I could create a branch that seeds the app with some test data or something.
da...@google.com <da...@google.com> #36
I was able to successful run the Tasks app but indeed haven't had luck reproducing the issue, so if you do end up creating that branch with seed data I will gladly use it.
Reading data via a Flow
returned from a @Dao
has never required a transaction, unless specified in the DAO via @Transaction
. Would love to hear more about the surprising performance issues.
However, I agree that transactions tend to be a source of performance issues. If no driver is used Room uses SupportSQLite
and Android's SQLite bindings, transactions there always use the single primary connection and they block each other. When using the AndroidSQLiteDriver
, similarly that uses Android's SQLite binding which will also uses the primary connection. There is a difference in code paths when no driver is specified and when AndroidSQLiteDriver
is used, but it is in terms of backwards compatibility of other SupportSQLite
APIs (see warning in
Now BundledSQLiteDriver
internally does not have a connection pool like the Android driver does and instead relies on Room's which we try to test as much as we can but of course it is not as mature's as Android. So we really appreciate you trying it out and reporting these issues. As for how different it is, the main difference is that the connection pool is suspending, other coroutines can continue while a connection is being used, this is very different from the other drivers that will 'block' the caller which for DAO functions Room alleviates by using a FIFO single threaded pool (the transaction executor) but can't control when other blocking APIs are used (beginTransaction). So yes, it is possible to start multiple transactions with Room's connection pool, but in essence they are also queued via suspending coroutines as the connection is being acquired and returned to the pool.
ba...@gmail.com <ba...@gmail.com> #37
Reading data via a Flow returned from a @Dao has never required a transaction, unless specified in the DAO via @Transaction. Would love to hear more about the surprising performance issues.
The issue we were having was that on startup our sync loop would sometimes start a transaction before our UI created a Room flow, and the UI flow would be blocked until the sync transaction finished. I think we jumped to the conclusion that Room flows acquire a transaction when they're started, but I just looked at the library code again and I think its just acquiring a transaction the first time you observe a table 🤦 edit: OK I'll stop derailing this ticket, but when a flow is started and its the first observer on a table there is a transaction, and when a flow finishes and its the last observer on a table there is a transaction
I was able to successful run the Tasks app but indeed haven't had luck reproducing the issue, so if you do end up creating that branch with seed data I will gladly use it.
I will get this to you ASAP
da...@google.com <da...@google.com> #38
Yes, if a Flow
needs to observe tables that have no observer 'installed' then Room has to create some TRIGGERs to start observing the tables and it does it in a transaction. Unfortunately this has to block the Flow
's initial query to guarantee consistency. I think we would need a different invalidation system, not TRIGGER based, to possibly avoid that start and end transaction but I don't think we have enough strong compelling reasons to change the system.
al...@beeper.com <al...@beeper.com> #39
I have attached a backup file that you can import into Tasks by tapping on 'Settings > Backups > Import' and selecting the file.
On my CAT S22 with BundledSQLiteDriver
it crashes with a database locked error, and the
The next-worst phone I have is a Galaxy S9 and I cannot get the database locked error on there, even with 10x as much data in the database
When I look at Firebase, these are the types of phones experiencing this crash: TP-Link Neffos A5 Tinno Y52 ZTE Blade A34 Moto E13 & E20 Xiamo Redmi A1 & A2 Alcatel 1C Transsion Tecno Spark Go 1 Mobiwire Smart C11
This list is not exhaustive, I just grabbed it from the first 5 distinct crashes. I've never even heard of most of these phones until just now
ae...@gmail.com <ae...@gmail.com> #40
Thank you for participating. I am really glad to see some progress and discussion on this issue.
ap...@google.com <ap...@google.com> #41
Project: platform/frameworks/support
Branch: androidx-main
Author: Daniel Santiago Rivera <
Link:
Reduce no-op transaction while syncing triggers
Expand for full commit details
Reduce no-op transaction while syncing triggers
The ObservedTableStates instance will return a list of observe operations (add or remove triggers) to perform if it 'needs sync'. A sync is required if at least a trigger needs to be added or removed from a table since the last sync. However, it might be that multiple observers are added and removed such that the end result of operations is actually to do nothing. In this case Room still tries to start a database transaction to not add or remove any triggers. Since transactions have lock implications it is best to avoid the transaction that if all observer operations are no-op.
Example case this change is optimizing:
1. Flow A in UI begins collecting, trigger A is installed
2. UI is rotated, not using collectAsStateWithLifecycle() or equivalent
2.a Flow A stops collecting, a sync is required
2.b Flow A starts collecting, a sync is still required
3. Triggers are synced, operation on table A is no-op
Bug: 380088809
Test: Existing
Change-Id: Iae612a1c4f8b8f1e8e15d2f60eb9bf68241570ef
Files:
- M
room/room-runtime/src/commonMain/kotlin/androidx/room/InvalidationTracker.kt
Hash: a0e5f03fe83ec6446228a4b872f1d72fb2bf8216
Date: Thu Jan 23 11:06:08 2025
ae...@gmail.com <ae...@gmail.com> #42
Are you were able to reproduce the issue and fix it or it is an other issue got fixed?
al...@beeper.com <al...@beeper.com> #43
I've spent an hour trying to repro the deadlock I mentioned in PRAGMA busy_timeout = <time in ms>
with the CAT S22. I have not been successful, so maybe that does fix my problem. I'm going to try releasing with BundledSQLiteDriver
again 🤞
ae...@gmail.com <ae...@gmail.com> #44
Hi. Are there any updates on this?
da...@google.com <da...@google.com> #45
Hey - 2.7.0-alpha13 has a change that should reduce the issue, but not guaranteed.
But I was not able to reproduce the issue with the project and data from
Things got busy so I have to dedicate more time to this issue, but its sort of a wild goose chase without a reliable repro.
ck...@gmail.com <ck...@gmail.com> #46
Starting with the latest version, 2.7.0-alpha13, we switched to BundledSQLiteDriver,
which produces hundreds of database-locked exceptions.
Non-fatal Exception: android.database.SQLException: Error code: 5, message: database is locked
at androidx.sqlite.driver.bundled.BundledSQLiteStatementKt.nativeStep(BundledSQLiteStatement.jvmAndroid.kt)
at androidx.sqlite.driver.bundled.BundledSQLiteStatementKt.access$nativeStep(BundledSQLiteStatement.jvmAndroid.kt)
at androidx.sqlite.driver.bundled.BundledSQLiteStatement.step(BundledSQLiteStatement.jvmAndroid.kt:100)
at app.resubs.core.database.dao.PendingNotificationDao_Impl.getAll$lambda$1(PendingNotificationDao_Impl.kt:94)
at androidx.room.util.DBUtil__DBUtil_androidKt$performSuspending$lambda$1$$inlined$internalPerform$1.invokeSuspend(DBUtil.kt:68)
at androidx.room.util.DBUtil__DBUtil_androidKt$performSuspending$lambda$1$$inlined$internalPerform$1.invoke(DBUtil.kt:8)
at androidx.room.util.DBUtil__DBUtil_androidKt$performSuspending$lambda$1$$inlined$internalPerform$1.invoke(DBUtil.kt:4)
at androidx.room.coroutines.ConnectionPoolImpl$useConnection$4.invokeSuspend(ConnectionPoolImpl.kt:144)
at androidx.room.coroutines.ConnectionPoolImpl$useConnection$4.invoke(ConnectionPoolImpl.kt:8)
at androidx.room.coroutines.ConnectionPoolImpl$useConnection$4.invoke(ConnectionPoolImpl.kt:4)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:43)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:166)
at kotlinx.coroutines.BuildersKt.withContext(Builders.kt)
at androidx.room.coroutines.ConnectionPoolImpl.useConnection(ConnectionPoolImpl.kt:144)
at androidx.room.coroutines.ConnectionPoolImpl$useConnection$1.invokeSuspend(ConnectionPoolImpl.kt:13)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Scopes.kt:35)
ae...@gmail.com <ae...@gmail.com> #47
Hi
da...@google.com <da...@google.com> #48
I did found that we were not configuring the busy_timeout in the initial connection which can lead to SQLITE_BUSY (error code 5). I've sent a cl to fix that.
I have another alternative / workaround for those with this issue which will also hint me to the root of the cause. In
val actualDriver = BundledSQLiteDriver()
val driverWrapper =
object : SQLiteDriver by actualDriver {
override fun open(fileName: String): SQLiteConnection {
return actualDriver.open(fileName).also { newConnection ->
newConnection.execSQL("PRAGMA busy_timeout = $customBusyTimeout")
}
}
}
roomDatabaseBuilder
.setDriver(driverWrapper)
Let me know if this helps or not.
ae...@gmail.com <ae...@gmail.com> #49
Hi
ap...@google.com <ap...@google.com> #50
Project: platform/frameworks/support
Branch: androidx-main
Author: Daniel Santiago Rivera <
Link:
Apply busy_timeout config for initial connection
Expand for full commit details
Apply busy_timeout config for initial connection
Fix an issue where busy_timeout was not being configured in the initial connection where schema validation is also done. The busy_timeout must be set on all connections to avoid SQLITE_BUSY.
Bug: 380088809
Test: BaseBuilderTest#setCustomBusyTimeout
Change-Id: I9320856f64363b05bcf6407eed0efe36ef3312a3
Files:
- M
room/integration-tests/multiplatformtestapp/src/commonTest/kotlin/androidx/room/integration/multiplatformtestapp/test/BaseBuilderTest.kt
- M
room/room-runtime/src/commonMain/kotlin/androidx/room/RoomConnectionManager.kt
- M
room/room-runtime/src/commonMain/kotlin/androidx/room/coroutines/ConnectionPool.kt
Hash: ba379355137898cf40a16bff549863ab6a55f093
Date: Mon Feb 10 09:32:51 2025
ae...@gmail.com <ae...@gmail.com> #51
Hi. I have applied this fix to my app and release for 10% of users. I got 4000 installs and for now I don't see this error. I am going to try with version 2.7.0-rc01.
se...@scrapgolem.com <se...@scrapgolem.com> #52
I'm still seeing this or a similar issue on 2.7.0-rc01. I haven't tried using AndroidSQLiteDriver
or any of the other workarounds listed here. Previously, I was using setQueryCoroutineContext(Dispatchers.IO.limitedParallelism(1))
which did solve the problem. I removed that after upgrading to 2.7.0-rc01.
I got this crash yesterday:
android.database.SQLException: Error code: 5, message: database is locked
at androidx.sqlite.driver.bundled.BundledSQLiteStatementKt.nativeStep(SourceFile)
at androidx.sqlite.driver.bundled.BundledSQLiteStatementKt.access$nativeStep(BundledSQLiteStatement.jvmAndroid.kt:0)
at androidx.sqlite.driver.bundled.BundledSQLiteStatement.step(BundledSQLiteStatement.jvmAndroid.kt:0)
at androidx.sqlite.driver.bundled.BundledSQLiteStatement.step(BundledSQLiteStatement.jvmAndroid.kt:100)
at androidx.sqlite.SQLite.execSQL(com.google.android.gms:play-services-mlkit-barcode-scanning@@18.3.1:56)
at androidx.room.coroutines.PooledConnectionImpl.endTransaction(ConnectionPoolImpl.kt:420)
at androidx.room.coroutines.PooledConnectionImpl.transaction(ConnectionPoolImpl.kt:388)
at androidx.room.coroutines.PooledConnectionImpl.isRecycled(ConnectionPoolImpl.kt:0)
at androidx.room.coroutines.PooledConnectionImpl.access$isRecycled(ConnectionPoolImpl.kt:0)
at androidx.room.coroutines.PooledConnectionImpl.withTransaction(ConnectionPoolImpl.kt:0)
at androidx.room.coroutines.PooledConnectionImpl.withTransaction(ConnectionPoolImpl.kt:344)
at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED
at androidx.room.util.DBUtil__DBUtil_androidKt$performInTransactionSuspending$3$invokeSuspend$$inlined$internalPerform$1.invokeSuspend(DBUtil.kt:0)
at androidx.room.util.DBUtil__DBUtil_androidKt$performInTransactionSuspending$3$invokeSuspend$$inlined$internalPerform$1.invokeSuspend(DBUtil.kt:59)
at androidx.room.util.DBUtil__DBUtil_androidKt$performInTransactionSuspending$3$invokeSuspend$$inlined$internalPerform$1.invoke(DBUtil.kt:0)
at androidx.room.util.DBUtil__DBUtil_androidKt$performInTransactionSuspending$3$invokeSuspend$$inlined$internalPerform$1.invoke(DBUtil.kt:0)
at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED
at androidx.room.coroutines.ConnectionPoolImpl$useConnection$4.invokeSuspend(ConnectionPoolImpl.kt:0)
at androidx.room.coroutines.ConnectionPoolImpl$useConnection$4.invokeSuspend(ConnectionPoolImpl.kt:144)
at androidx.room.coroutines.ConnectionPoolImpl$useConnection$4.invoke(ConnectionPoolImpl.kt:0)
at androidx.room.coroutines.ConnectionPoolImpl$useConnection$4.invoke(ConnectionPoolImpl.kt:0)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(ChildStackFactory.kt:43)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext
at kotlinx.coroutines.BuildersKt.withContext(DebugStrings.kt:0)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext
at kotlinx.coroutines.BuildersKt.withContext(DebugStrings.kt:1)
at androidx.room.coroutines.ConnectionPoolImpl.useConnection(ConnectionPoolImpl.kt:144)
at androidx.room.RoomDatabase.useConnection$room_runtime_release(RoomDatabase.android.kt:0)
at androidx.room.RoomConnectionManager.useConnection
at androidx.room.RoomDatabase.useConnection$room_runtime_release(RoomDatabase.android.kt:587)
at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED
at androidx.room.util.DBUtil__DBUtil_androidKt$performInTransactionSuspending$3.invokeSuspend(DBUtil.android.kt:0)
at androidx.room.util.DBUtil__DBUtil_androidKt$performInTransactionSuspending$3.invokeSuspend(DBUtil.android.kt:243)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:0)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)
Description
Component used: RoomDB
Version used: Room - 2.7.0-alpha11, sqlite-bundled - 2.5.0-alpha11
Devices/Android versions reproduced on: Transsion Tecno, Nokia C21 Plus, Redmi A1+. Android 11-14.
Crash stack:
Please fix it.