Status Update
Comments
ae...@gmail.com <ae...@gmail.com> #2
Lint options:
lintOptions {
lintConfig = file('lint.xml')
abortOnError true
xmlReport true
htmlReport true
checkDependencies true
}
Also, our project has custom lint rules. Failure happens with a dependency of 26.6.3 and 27.0.0.
Is any way to downgrade lint runner? This problem is keeping us from using AGP 4.0
el...@google.com <el...@google.com> #3
Attached slightly different stacktrace for the same problem.
Wonder if disabling some lint rules could help to "fix" this problem, as it is also blocking for us 4.0 AGP upgrade.
ae...@gmail.com <ae...@gmail.com> #4
Notes:
I suspect the exceptions are happening now because JetBrains recently changed an assert
statement into a hard failure (see
I.e., it's possible that Lint has been hitting this code path all along, and only now it is causing a problem.
This has been difficult to investigate so far because the failure is nondeterministic and also deep inside the Kotlin compiler. Plus, JetBrains seems to be hitting this code path occasionally too (hence why they changed the assert into a hard failure), so I'm not even sure whether Lint is implicated or not.
ae...@gmail.com <ae...@gmail.com> #5
It could also explain why not all lint rules were working from time to time (
Is any public issue created I could follow?
ae...@gmail.com <ae...@gmail.com> #6
Has anyone tried this with 4.1.0-beta2? We're using a more recent version of UAST and the Kotlin compiler there. It's not clear that it's fixed but -- there's a chance :-)
ae...@gmail.com <ae...@gmail.com> #7
I tried. The same error. I am wondering, is any way to know which lint checks cause failure? I have a few custom lint checks. Or, is any way downgrade compiler for lint checks?
ae...@gmail.com <ae...@gmail.com> #8
I did more tests and probably narrow down a cause. I did all tests on 4.1.0-beta2
. Original configuration have enabled checkDependencies
and included custom lint checks. Custom lint checks are compiled using 26.6.3
version:
checkDependencies = true, customLintChecks = true
= 20% chance of successcheckDependencies = true, customLintChecks = false
= 57% chance of successcheckDependencies = false, customLintChecks = true
= 100% chance of success
It is a clear evidence that checkDependencies
feature is not stable. In addition, custom lint checks is not friendly with checkDependencies
and increases the risk of failure. Or maybe just an old lint SDK used is to blame.
It is very similar to
I have a theory, but do not know how to test. Maybe crashes happening because there are some lint checks from libs built upon old lint SDK version?
ae...@gmail.com <ae...@gmail.com> #9
To me this is happening on 4.2.0-alpha04 too.
Can someone confirm that this is happening if you have these three conditions met?:
- checkDependencies=true on your app module
- have a custom lint rule using lintChecks on your app module
- have a custom lint rule using lintChecks on your library module
For me the error went away after I removed the lintChecks on the library module.
da...@google.com <da...@google.com> #10
could you clarify exactly what you mean in these?
have a custom lint rule using lintChecks on your app module have a custom lint rule using lintChecks on your library module
By this I mean a declaration in your modules dependency block:
lintChecks project(":features:language_lint")
ae...@gmail.com <ae...@gmail.com> #11
As opposed to lintPublish
? Or is that not relevant?
ae...@gmail.com <ae...@gmail.com> #12
For me this is for local checks so I'm using lintChecks. Removing lintChecks from the library module and only applying it on the app module fixed the lint crash. However that's not optimal as I want to run the lint checks individually on the library module as well. It would not be interesting if this is really the cause of the issue or if it doesn't fix it for others.
ae...@gmail.com <ae...@gmail.com> #13
I do not have any custom lint checks declared but there might be a transient lint check pulled in.
ae...@gmail.com <ae...@gmail.com> #14
We have checkDependencies=true
on our app module and apply there custom lint checks. Disabling custom lint checks has not solved the issue, though we have more custom lint checks via external dependencies (for example, timber).
ae...@gmail.com <ae...@gmail.com> #15
#14, could you check with checkDependencies=false
? It fixes problem on my project. Would be nice to hear more proves.
da...@google.com <da...@google.com> #16
#15, I've set checkDependencies = false
, but left our custom lint checks enabled. So far lint finished successfully without issue errors.
ae...@gmail.com <ae...@gmail.com> #17
In my case, all builds of the >50 were a success after checkDependencies = false
. However, disabling checkDependencies
is not a solution as well. Since all our code is split in small logical modules, there is no point in lint. Too many false-positives and true-negatives.
da...@google.com <da...@google.com> #18
I cherry-picked a change to 4.1 Beta 4 which essentially changes this error into a logged warning rather than a hard failure. That does not "fix" the problem, but it at least gets us back to the behavior of 3.6. Can someone confirm that this workaround has worked for them?
Also, I think I know what the root cause is (see notes below). However, it's hard to be sure without a repro scenario. Would anyone be willing to share an open-source project that reproduces this bug? (You can also send the project to
Notes:
-
My current theory is that this bug is related to
.https://issuetracker.google.com/159733104#comment6
I.e., I think Lint should not be reusing the same Kotlin compiler environment to analyze multiple modules, which is what we do whencheckDependencies=true
. -
It is still strange that the failure is nondeterministic. However, one potential reason is that the Kotlin compiler caches many things via
SoftReference
.
ae...@gmail.com <ae...@gmail.com> #19
Sorry for my long delay. I was tried with 4.1.0-beta05
(newest version to date), and the problem is still here. I added new log in case lines were changed.
Would anyone be willing to share an open-source project that reproduces this bug?
I have only closed source project with this problem. Maybe someone knows some quite large multimodule opensource project I could try setup AGP with lint and try reproduction?
el...@google.com <el...@google.com>
ae...@gmail.com <ae...@gmail.com> #20
I tried to reproduce with two small multimodule projects, but all builds works flawlessly. Also, I tried to reproduce using checkDependencies
, and 6 other helper modules. 145k CLOC without tests. I suppose there is a good chance problem happen due to the cache.
It is still strange that the failure is nondeterministic.
It is even non-deterministic in CI/docker builds using the same fresh environment and exactly the same code each time. Build cache and daemon is disabled there. Multithreading should be involved as well.
In addition, I found in most cases failed due to the same file
ae...@gmail.com <ae...@gmail.com> #21
da...@google.com <da...@google.com> #22
There are some architectural changes coming in Lint that will fix this properly, but they will not make it into 4.2.
However, there is another workaround you can try that will be available starting in AGP 4.2 Beta 4.
Essentially you can tell Lint to "reset" the Kotlin compiler between each module analysis, thereby clearing all caches. I did not make this the default behavior because the effect on performance is unknown/risky.
To enable this behavior, either set the environment variable LINT_DO_NOT_REUSE_UAST_ENV
to "true", or set the JVM system property lint.do.not.reuse.uast.env
to "true". For example, you can do this from the command line:
./gradlew -Dlint.do.not.reuse.uast.env=true :app:lintDebug
Or by putting this in your gradle.properties
file:
systemProp.lint.do.not.reuse.uast.env=true
ae...@gmail.com <ae...@gmail.com> #23
Status updates:
-
I'm still hoping someone can confirm whether the workaround in
worked for them in AGP 4.2.comment#22 -
Starting with AGP 7.0-alpha13 the root cause of this issue should be fixed completely due to the new "partial analysis" mode (enabled by default) in which Lint analyzes modules independently and merges results along the way. It fixes the issue because Lint will no longer use the same Kotlin compiler environment to analyze multiple modules (and so the risk of stale caches is gone).
da...@google.com <da...@google.com> #24
I'm still hoping someone can confirm whether the workaround in
worked for them in AGP 4.2. comment#22
This unfortunately did not work for us. We actually see lint crashes after enabling via systemProp.lint.do.not.reuse.uast.env=true
. See the attached log. It's also much slower, as expected.
AGP 4.2 seems to make this error much more frequent compared to 4.1, for some reason.
ae...@gmail.com <ae...@gmail.com> #25
Can you file a new bug? You can add a comment here linking to it.
ae...@gmail.com <ae...@gmail.com> #26
Sure. Without that workaround, we get the same
ERROR: package fragment is not found for module:<lint-module> is a module[ModuleDescriptorImpl@5e5e6c61] file:KtFile: LiveViewerViewData.kt
error in this ticket occasionally (1-2% of the time?).
ae...@gmail.com <ae...@gmail.com> #27
Oh, I misunderstood. So, using lint.do.not.reuse.uast.env
is what causes the new crash? That is unfortunate, and I will investigate. Let me know if there is a sample project you can share that reproduces the issue.
da...@google.com <da...@google.com> #28
Not sure if you still wanted the new bug, but here it is:
ae...@gmail.com <ae...@gmail.com> #29
FYI the issue in
And to confirm, lint.do.not.reuse.uast.env
should no longer be needed at all in AGP 7.0+.
ba...@gmail.com <ba...@gmail.com> #30
Thanks #29 . I am noticing that when this happens, after the error log for
package fragment is not found for module:<lintWithKotlin> is a module
There is another error
java.lang.IllegalArgumentException: Argument for @NotNull parameter 'descriptor' of org/jetbrains/kotlin/codegen/context/CodegenContext.intoPackagePart must not be null
at org.jetbrains.kotlin.codegen.context.CodegenContext.$$$reportNull$$$0(CodegenContext.java)
at org.jetbrains.kotlin.codegen.context.CodegenContext.intoPackagePart(CodegenContext.java)
at org.jetbrains.kotlin.asJava.builder.LightClassDataProviderForClassOrObject$computeLightClassData$1$1.invoke(LightClassDataProvider.kt:51)
at org.jetbrains.kotlin.asJava.builder.LightClassDataProviderForClassOrObject$computeLightClassData$1$1.invoke(LightClassDataProvider.kt:38)
at org.jetbrains.kotlin.asJava.builder.LightClassBuilderKt.buildLightClass(LightClassBuilder.kt:64)
at org.jetbrains.kotlin.asJava.builder.LightClassDataProviderForClassOrObject$computeLightClassData$1.invoke(LightClassDataProvider.kt:47)
at org.jetbrains.kotlin.asJava.builder.LightClassDataProviderForClassOrObject$computeLightClassData$1.invoke(LightClassDataProvider.kt:38)
at org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport.createDataHolderForClass(CliLightClassGenerationSupport.kt:64)
at org.jetbrains.kotlin.asJava.builder.LightClassDataProviderForClassOrObject.computeLightClassData(LightClassDataProvider.kt:45)
at org.jetbrains.kotlin.asJava.builder.LightClassDataProviderForClassOrObject.compute(LightClassDataProvider.kt:61)
at com.intellij.psi.impl.PsiCachedValueImpl.doCompute(PsiCachedValueImpl.java:54)
at com.intellij.util.CachedValueBase.lambda$getValueWithLock$1(CachedValueBase.java:235)
at com.intellij.openapi.util.RecursionManager$1.doPreventingRecursion(RecursionManager.java:113)
at com.intellij.openapi.util.RecursionManager.doPreventingRecursion(RecursionManager.java:72)
at com.intellij.util.CachedValueBase.getValueWithLock(CachedValueBase.java:236)
at com.intellij.psi.impl.PsiCachedValueImpl.getValue(PsiCachedValueImpl.java:43)
at
Does the fix address both of these?
ba...@gmail.com <ba...@gmail.com> #31
package fragment is not found
and Argument for @NotNull parameter...
), the workaround in 4.2 is to put
systemProp.lint.do.not.reuse.uast.env=true
in your gradle.properties
file as described in
ae...@gmail.com <ae...@gmail.com> #32
Marking fixed in AGP 7.0.
That is, the lint.do.not.reuse.uast.env
workaround should no longer be needed in AGP 7.0+. And, you should no longer see the following warnings/errors while running Lint:
ERROR: package fragment is not found for module:<lintWithKotlin>...
ERROR: Could not generate LightClass for...
java.lang.IllegalArgumentException: Argument for @NotNull parameter 'descriptor' of org/jetbrains/kotlin/codegen/context/CodegenContext.intoPackagePart must not be null
The issue is fixed due to the new "Lint partial analysis" mode (enabled by default) which creates a standalone UastEnvironment
instance for each module, thereby avoiding stale caches in the Kotlin compiler frontend.
Please comment on the bug if you see any similar errors in AGP 7.0+.
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)
ae...@gmail.com <ae...@gmail.com> #53
Hi. I got a new error: Fatal Exception: android.database.SQLException: Error code: 5, message: Timed out attempting to acquire a reader connection.
Writer pool:
Xu1@d088033 (capacity=1)
[1] - ow@e204ff0
Status: Free connection
Reader pool:
Xu1@6c0ec8f (capacity=4)
[1] - ow@dd27b1c
Status: Acquired connection
Coroutine: [go2@7c92325, eo2{Active}@cf76cfa, Dispatchers.IO]
Acquired:
at lR.C(Unknown Source:310)
at iR.invokeSuspend(Unknown Source:13)
at dq.resumeWith(Unknown Source:8)
at TR1.o(Unknown Source:6)
at W.resumeWith(Unknown Source:22)
at dq.resumeWith(Unknown Source:31)
at xc0.run(Unknown Source:109)
at K2.run(Unknown Source:1024)
at qc2.run(Unknown Source:2)
at SV.run(Unknown Source:93)
[2] - ow@71a2d08
Status: Free connection
[3] - ow@c0dcca1
Status: Free connection
[4] - ow@bbf5ec6
Status: Free connection
da...@google.com <da...@google.com> #54
"Timed out attempting to acquire a reader connection" is a better error than "database is locked", hehe
It seems you have 3 zombie connections in your pool. I suspect this is because currently don't refill the pool when a connection dies. I'll work on a change to make sure the pool is always of the correct size. Thanks again for your patience on helping us make the library better.
ap...@google.com <ap...@google.com> #55
Project: platform/frameworks/support
Branch: androidx-main
Author: Daniel Santiago Rivera <
Link:
Reimplement suspending pool with Semaphore
Expand for full commit details
Reimplement suspending pool with Semaphore
This changes the implementation of Room's connection pool to use a Semaphore instead of a Channel. It makes the implementation simpler and removes the possibility of connections getting 'lost' due the the various branches needed to handle when a channel send / receive fails.
The Channel was also used as a 'queue' instead a circular array is used to push and pop connections acquired and released into the pool. The semaphore still controls the amount of connections being locked and unlocked and is the suspending API that waits for a connection to be free.
Bug: 322386871
Bug: 380088809
Test: BaseConnectionPoolTest
Change-Id: I9b7f2d44b511eb3e3d8cdaf8cb8905bb6203f8c5
Files:
- M
room/room-runtime/src/commonMain/kotlin/androidx/room/coroutines/ConnectionPoolImpl.kt
- M
room/room-runtime/src/commonTest/kotlin/androidx/room/coroutines/BaseConnectionPoolTest.kt
Hash: dc4715197f7869c87af3025acba91a0c8a57db4d
Date: Mon Mar 17 12:01:10 2025
da...@google.com <da...@google.com> #56
The next release (2.7.0-rc03
) will have a change that should alleviate the 'Timed out attempting to acquire a reader connection
' issue, I'll continue to keep this issue open so others can report if they are still experiencing it or not.
ae...@gmail.com <ae...@gmail.com> #57
Hi. Thank you for your fixes. I have released 2.7.0-rc01
for 100% of users. For now it have about 22000 installs and I don't see the error SQLException: Error code: 5, message: database is locked
anymore.
ae...@gmail.com <ae...@gmail.com> #58
Hi. Got 1 android.database.SQLException: Error code: 5, message: database is locked
RoomDB: 2.7.0-rc03. Device: Oppo, Android 11
Note: before this was at native step, now I got it at nativePrepare.
Fatal Exception: android.database.SQLException: Error code: 5, message: database is locked
at androidx.sqlite.driver.bundled.BundledSQLiteConnectionKt.nativePrepare(BundledSQLiteConnection.jvmAndroid.kt)
at androidx.sqlite.driver.bundled.BundledSQLiteConnectionKt.access$nativePrepare(BundledSQLiteConnection.jvmAndroid.kt)
at androidx.sqlite.driver.bundled.BundledSQLiteConnection.prepare(BundledSQLiteConnection.jvmAndroid.kt:36)
at androidx.sqlite.SQLite.execSQL(SQLite.java:56)
at androidx.room.BaseRoomConnectionManager.configureSynchronousFlag(BaseRoomConnectionManager.java:156)
at androidx.room.BaseRoomConnectionManager.configurationConnection(BaseRoomConnectionManager.java:135)
at androidx.room.BaseRoomConnectionManager.access$configurationConnection(BaseRoomConnectionManager.java:36)
at androidx.room.BaseRoomConnectionManager$DriverWrapper.openLocked$lambda$1(BaseRoomConnectionManager.java:83)
at androidx.room.concurrent.ExclusiveLock.withLock(ExclusiveLock.java:50)
at androidx.room.BaseRoomConnectionManager$DriverWrapper.openLocked(BaseRoomConnectionManager.java:65)
at androidx.room.BaseRoomConnectionManager$DriverWrapper.open(BaseRoomConnectionManager.java:57)
at androidx.room.coroutines.ConnectionPoolImpl._init_$lambda$4(ConnectionPoolImpl.java:85)
at androidx.room.coroutines.Pool.tryOpenNewConnectionLocked(ConnectionPoolImpl.kt:234)
at androidx.room.coroutines.Pool.acquire(ConnectionPoolImpl.kt:219)
at androidx.room.coroutines.ConnectionPoolImpl$acquireWithTimeout$2.invokeSuspend(ConnectionPoolImpl.kt:171)
at androidx.room.coroutines.ConnectionPoolImpl$acquireWithTimeout$2.invoke(ConnectionPoolImpl.kt:12)
at androidx.room.coroutines.ConnectionPoolImpl$acquireWithTimeout$2.invoke(ConnectionPoolImpl.kt:12)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturnIgnoreTimeout(Undispatched.kt:54)
at kotlinx.coroutines.TimeoutKt.setupTimeout(Timeout.kt:149)
at kotlinx.coroutines.TimeoutKt.withTimeout(Timeout.kt:44)
at kotlinx.coroutines.TimeoutKt.withTimeout-KLykuaI(Timeout.kt:72)
at androidx.room.coroutines.ConnectionPoolImpl.useConnection(ConnectionPoolImpl.kt:542)
at androidx.room.RoomConnectionManager.useConnection(RoomConnectionManager.java:126)
at androidx.room.RoomDatabase.useConnection$room_runtime_release(RoomDatabase.android.kt:588)
at androidx.room.util.DBUtil__DBUtil_androidKt$performSuspending$$inlined$compatCoroutineExecute$DBUtil__DBUtil_androidKt$1.invokeSuspend(DBUtil.android.kt:109)
at androidx.room.util.DBUtil__DBUtil_androidKt$performSuspending$$inlined$compatCoroutineExecute$DBUtil__DBUtil_androidKt$1.invoke(DBUtil.android.kt:12)
at androidx.room.util.DBUtil__DBUtil_androidKt$performSuspending$$inlined$compatCoroutineExecute$DBUtil__DBUtil_androidKt$1.invoke(DBUtil.android.kt:12)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:43)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(BuildersKt__Builders_common.kt:166)
at kotlinx.coroutines.BuildersKt.withContext(Builders.kt:1)
at androidx.room.util.DBUtil__DBUtil_androidKt.performSuspending(DBUtil__DBUtil_android.kt:247)
at androidx.room.util.DBUtil.performSuspending(DBUtil.java:1)
at androidx.room.coroutines.FlowUtil$createFlow$$inlined$map$1$2.emit(Emitters.kt:224)
at kotlinx.coroutines.flow.FlowKt__ChannelsKt.emitAllImpl$FlowKt__ChannelsKt(FlowKt__Channels.kt:33)
at kotlinx.coroutines.flow.FlowKt__ChannelsKt.access$emitAllImpl$FlowKt__ChannelsKt(FlowKt__Channels.kt:1)
at kotlinx.coroutines.flow.FlowKt__ChannelsKt$emitAllImpl$1.invokeSuspend(Channels.kt:11)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
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)
ae...@gmail.com <ae...@gmail.com> #59
I also got 1 exception: android.database.SQLException: Error code: 5, message: Timed out attempting to acquire a writer connection.
Fatal Exception: android.database.SQLException: Error code: 5, message: Timed out attempting to acquire a writer connection.
Writer pool:
fv1@6e0810d (capacity=1, permits=0, queue=(size=0)[], )
[1] - Aw@1f718c2
Status: Acquired connection
Coroutine: [Ac0{Active}@7ccd6d3, Dispatchers.IO]
Acquired:
at xR.C(Unknown Source:328)
at iK1.w(Unknown Source:6)
at il2.h(Unknown Source:77)
at Wk2.invokeSuspend(Unknown Source:28)
at pq.resumeWith(Unknown Source:8)
at Bc0.run(Unknown Source:109)
at K2.run(Unknown Source:1024)
at wc2.run(Unknown Source:2)
at fW.run(Unknown Source:93)
Reader pool:
fv1@7a12109 (capacity=4, permits=4, queue=(size=0)[], )
[1] - null
[2] - null
[3] - null
[4] - null
at androidx.sqlite.SQLite.throwSQLiteException(SQLite.java:67)
at androidx.room.coroutines.ConnectionPoolImpl.throwTimeoutException(ConnectionPoolImpl.kt:191)
at androidx.room.coroutines.ConnectionPoolImpl.useConnection(ConnectionPoolImpl.kt:142)
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)
at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:101)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
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)
ae...@gmail.com <ae...@gmail.com> #60
And also I got 10 java.lang.UnsatisfiedLinkError: dlopen failed: library "libsqliteJni.so" not found
Maybe it may be linked with nativePrepare error?
Fatal Exception: java.lang.UnsatisfiedLinkError: dlopen failed: library "libsqliteJni.so" not found
at java.lang.Runtime.loadLibrary0(Runtime.java:1131)
at java.lang.Runtime.loadLibrary0(Runtime.java:1051)
at java.lang.System.loadLibrary(System.java:1664)
at androidx.sqlite.driver.bundled.NativeLibraryLoader.loadLibrary(NativeLibraryLoader.java:21)
at androidx.sqlite.driver.bundled.BundledSQLiteDriver$NativeLibraryObject.<clinit>(BundledSQLiteDriver.jvmAndroid.kt:62)
at androidx.sqlite.driver.bundled.BundledSQLiteDriver.open(BundledSQLiteDriver.java:55)
at androidx.sqlite.driver.bundled.BundledSQLiteDriver.open(BundledSQLiteDriver.java:42)
at androidx.room.BaseRoomConnectionManager$DriverWrapper.openLocked$lambda$1(BaseRoomConnectionManager.java:72)
at androidx.room.concurrent.ExclusiveLock.withLock(ExclusiveLock.java:50)
at androidx.room.BaseRoomConnectionManager$DriverWrapper.openLocked(BaseRoomConnectionManager.java:65)
at androidx.room.BaseRoomConnectionManager$DriverWrapper.open(BaseRoomConnectionManager.java:57)
at androidx.room.coroutines.ConnectionPoolImpl._init_$lambda$5(ConnectionPoolImpl.java:92)
at androidx.room.coroutines.Pool.tryOpenNewConnectionLocked(ConnectionPoolImpl.kt:234)
at androidx.room.coroutines.Pool.acquire(ConnectionPoolImpl.kt:219)
at androidx.room.coroutines.ConnectionPoolImpl$acquireWithTimeout$2.invokeSuspend(ConnectionPoolImpl.kt:171)
at androidx.room.coroutines.ConnectionPoolImpl$acquireWithTimeout$2.invoke(ConnectionPoolImpl.kt:12)
at androidx.room.coroutines.ConnectionPoolImpl$acquireWithTimeout$2.invoke(ConnectionPoolImpl.kt:12)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturnIgnoreTimeout(Undispatched.kt:54)
at kotlinx.coroutines.TimeoutKt.setupTimeout(Timeout.kt:149)
at kotlinx.coroutines.TimeoutKt.withTimeout(Timeout.kt:44)
at kotlinx.coroutines.TimeoutKt.withTimeout-KLykuaI(Timeout.kt:72)
at androidx.room.coroutines.ConnectionPoolImpl.useConnection(ConnectionPoolImpl.kt:542)
at androidx.room.RoomConnectionManager.useConnection(RoomConnectionManager.java:126)
at androidx.room.RoomDatabase.useConnection$room_runtime_release(RoomDatabase.android.kt:588)
at androidx.room.TriggerBasedInvalidationTracker.syncTriggers$room_runtime_release(InvalidationTracker.kt:300)
at androidx.room.TriggerBasedInvalidationTracker$createFlow$1$1.invokeSuspend(InvalidationTracker.kt:233)
at androidx.room.TriggerBasedInvalidationTracker$createFlow$1$1.invoke(InvalidationTracker.kt:12)
at androidx.room.TriggerBasedInvalidationTracker$createFlow$1$1.invoke(InvalidationTracker.kt:12)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:43)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(BuildersKt__Builders_common.kt:166)
at kotlinx.coroutines.BuildersKt.withContext(Builders.kt:1)
at androidx.room.TriggerBasedInvalidationTracker$createFlow$1.invokeSuspend(InvalidationTracker.kt:233)
at androidx.room.TriggerBasedInvalidationTracker$createFlow$1.invoke(InvalidationTracker.kt:12)
at androidx.room.TriggerBasedInvalidationTracker$createFlow$1.invoke(InvalidationTracker.kt:12)
at kotlinx.coroutines.flow.SafeFlow.collectSafely(SafeFlow.java:57)
at kotlinx.coroutines.flow.AbstractFlow.collect(AbstractFlow.java:226)
at kotlinx.coroutines.flow.internal.ChannelFlowOperatorImpl.flowCollect(ChannelFlow.kt:191)
at kotlinx.coroutines.flow.internal.ChannelFlowOperator.collectTo$suspendImpl(ChannelFlow.kt:153)
at kotlinx.coroutines.flow.internal.ChannelFlowOperator.collectTo(ChannelFlow.kt:5)
at kotlinx.coroutines.flow.internal.ChannelFlow$collectToFun$1.invokeSuspend(ChannelFlow.kt:56)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
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)
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.