firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.26k stars 572 forks source link

SQLiteEventStore.lambda$ensureBeginTransaction$24: android.database.sqlite.SQLiteDatabaseLockedException - database is locked (code 5 SQLITE_BUSY) #6001

Closed lklong1551019 closed 3 months ago

lklong1551019 commented 4 months ago

[READ] Step 1: Are you in the right place?

Issues filed here should be about bugs in the code in this repository. If you have a general question, need help debugging, or fall into some other category use one of these other channels:

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

After updating firebase bom from 30.3.1 to 31.2.3 and now 32.8.0, for the past few months we have been experiencing random crashes (~ 400 crashes per day) on a variety of devices, across every android version, with 94% events happened while in background. It can happen when the app has just run for 10 seconds, or even for a long time. This crash starts to happen after:

We cannot reproduce this. Here is an example stack trace:

Fatal Exception: com.google.android.datatransport.runtime.synchronization.SynchronizationException
Timed out while trying to acquire the lock.
Fatal Exception: com.google.android.datatransport.runtime.synchronization.SynchronizationException: Timed out while trying to acquire the lock.
       at com.google.android.datatransport.runtime.synchronization.SynchronizationException.<init>(SynchronizationException.java:20)
       at com.google.android.datatransport.runtime.scheduling.persistence.SQLiteEventStore.lambda$ensureBeginTransaction$25(SQLiteEventStore.java:759)
       at com.google.android.datatransport.runtime.scheduling.persistence.SQLiteEventStore.retryIfDbLocked(SQLiteEventStore.java:585)
       at com.google.android.datatransport.runtime.scheduling.persistence.SQLiteEventStore.ensureBeginTransaction(SQLiteEventStore.java:753)
       at com.google.android.datatransport.runtime.scheduling.persistence.SQLiteEventStore.runCriticalSection(SQLiteEventStore.java:766)
       at com.google.android.datatransport.runtime.scheduling.jobscheduling.Uploader.logAndUpdateState(Uploader.java:164)
       at com.google.android.datatransport.runtime.ForcedSender.sendBlocking(ForcedSender.java:36)
       at com.google.firebase.crashlytics.internal.send.ReportQueue.lambda$flushScheduledReportsIfAble$0(ReportQueue.java:138)
       at java.lang.Thread.run(Thread.java:919)

Caused by android.database.sqlite.SQLiteDatabaseLockedException
database is locked (code 5 SQLITE_BUSY)
Caused by android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5 SQLITE_BUSY)
       at android.database.sqlite.SQLiteConnection.nativeExecute(SQLiteConnection.java)
       at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:648)
       at android.database.sqlite.SQLiteSession.beginTransactionUnchecked(SQLiteSession.java:325)
       at android.database.sqlite.SQLiteSession.beginTransaction(SQLiteSession.java:300)
       at android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:568)
       at android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:478)
       at com.google.android.datatransport.runtime.scheduling.persistence.SQLiteEventStore.lambda$ensureBeginTransaction$24(SQLiteEventStore.java:755)
       at com.google.android.datatransport.runtime.scheduling.persistence.SQLiteEventStore.retryIfDbLocked(SQLiteEventStore.java:582)
       at com.google.android.datatransport.runtime.scheduling.persistence.SQLiteEventStore.ensureBeginTransaction(SQLiteEventStore.java:753)
       at com.google.android.datatransport.runtime.scheduling.persistence.SQLiteEventStore.runCriticalSection(SQLiteEventStore.java:766)
       at com.google.android.datatransport.runtime.scheduling.jobscheduling.Uploader.logAndUpdateState(Uploader.java:164)
       at com.google.android.datatransport.runtime.ForcedSender.sendBlocking(ForcedSender.java:36)
       at com.google.firebase.crashlytics.internal.send.ReportQueue.lambda$flushScheduledReportsIfAble$0(ReportQueue.java:138)
       at java.lang.Thread.run(Thread.java:919)

Here are some screenshots:

image image image image

Is there anything we could do ? Any insight would be appreciated.

google-oss-bot commented 4 months ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

lehcar09 commented 4 months ago

Hi @lklong1551019, thank you for reaching out. Prior Firebase SDK version 31.3.0, the flushScheduledReportsIfAble was not catching errors with SQLExceptions. The fix (#4608) was included in the version BOM v31.3.0. You mentioned that you are using v32.8.0, did you notice if the issue has been reduced?

lklong1551019 commented 4 months ago

Hi @lehcar09 , unfortunately the issue has not been reduced at all

here is a snapshot of my project structure for additional info

image
lklong1551019 commented 4 months ago

Hi @lehcar09 , here are some more insights on our crashlytics:

lehcar09 commented 4 months ago

Thank you for the details @lklong1551019. I'll notify our engineers and see what we can do here.

In the meantime, I would suggest using the latest Firebase SDK version to get the latest bug fixes and features.

lklong1551019 commented 3 months ago

Thank you, glad to hear that. I'm looking forward to hearing updates. Cheers.

lehcar09 commented 3 months ago

Related issue #6010.

anitdas commented 3 months ago

Hi @lklong1551019! This issue is fixed in the latest bom (33.1.0). If you see this issue after updating, please file a new bug! Thanks :)

lklong1551019 commented 3 months ago

Hi @anitdas , unfortunately we still have this issue so I just filed a new bug. I'm looking forward to hearing updates, thanks.