rudderlabs / rudder-sdk-android

Android SDK for RudderStack - the Customer Data Platform for Developers.
https://www.rudderstack.com
Other
18 stars 29 forks source link

BUG : Fatal Exception: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (Sqlite code 14): Could not open database, (OS error - 2:No such file or directory) #479

Closed jiebo closed 1 month ago

jiebo commented 2 months ago

Describe the bug From our Firebase Crashlytics, we are seeing an issue that seems to be caused by DefaultPersistence.getWritableDatabase. Please check the stack trace below.

Stack Trace

Fatal Exception: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (Sqlite code 14): Could not open database, (OS error - 2:No such file or directory)
       at android.database.sqlite.SQLiteConnection.nativeOpen(SQLiteConnection.java)
       at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:223)
       at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:207)
       at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:511)
       at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:194)
       at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:183)
       at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:880)
       at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:864)
       at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:767)
       at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:739)
       at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:289)
       at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:235)
       at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:175)
       at com.rudderstack.android.sdk.core.persistence.DefaultPersistence.getWritableDatabase(DefaultPersistence.java:54)
       at com.rudderstack.android.sdk.core.persistence.DefaultPersistence.isAccessible(DefaultPersistence.java:261)
       at com.rudderstack.android.sdk.core.DBPersistentManager.checkIfColumnExists(DBPersistentManager.java:487)
       at com.rudderstack.android.sdk.core.DBPersistentManager.lambda$checkForMigrations$2(DBPersistentManager.java:519)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
       at java.lang.Thread.run(Thread.java:776)

Over the past 7 days, we've recorded 43k crashes for 447 users. Here are the device details

Version of the Android SDK We're using 1.22.0 of the Rudderstack Android SDK.

Mobile device mode integration

rudderstack-android-sdk-core = { module = "com.rudderstack.android.sdk:core", version.ref = "rudderstack" }

SDK initialisation snippet

    fun build(): RudderClient {
        return RudderClient.getInstance(
            context,
            key,
            RudderConfig.Builder()
                .withDataPlaneUrl(domain)
                .withRecordScreenViews(false)
                .withLogLevel(RudderLogLevel.NONE)
                .build()
        )
    }

Check for Correct Usage of writeKey and dataPlaneUrl Events are flowing as expected

1abhishekpandey commented 2 months ago

Hey @jiebo,

Thanks for raising this issue.

I investigated this issue, and it appears to be caused by the storage permission not being granted. The problem occurs right when the Rudder Android SDK initialization starts.

For now, could you please try the following steps:

  1. Ensure the following permission is added to your app (if it’s not already included). You can refer to the thread here: https://stackoverflow.com/a/19783139.
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  2. Update the Rudder Android SDK to the latest version v1.25.0.

Additionally, I would like to clarify a few points:

  1. Do you have the logic to initialise the SDK in the background?
  2. Have you been able to track any events using the Amazon device?
  3. What type of Amazon device is experiencing this issue?
  4. Have you noticed this error on other Android devices as well?
  5. Since we do not have an Amazon device to reproduce the issue, could you suggest if there is any simulator we could use for testing? Any steps or suggestions regarding that would be appreciated.
  6. Have you been able to reproduce this issue on your end?
1abhishekpandey commented 2 months ago

Hey @jiebo,

Could you please provide the information requested above?

jiebo commented 2 months ago

Hi @1abhishekpandey, sorry for the delayed response. We updated the Adapty SDK version to 1.25.0 but the issue is still persisting. Also, we already have the WRITE_EXTERNAL_STORAGE permission added.

For the next few points you requested:

  1. Nope, we don't initialise the SDK in the background, only on app start
  2. We're unable to verify this because we don't collect the user's device manufacturer
  3. 46% - Fire TV Stick 4K Max - 1st Gen (2021), 14% - Fire TV Stick - 3rd Gen (2020), 11% - Nebula Soundbar - Fire TV Edition (2019)
  4. Yes, a variety of TV devices, e.g., Xiaomi
  5. I'm not aware of any
  6. Unfortunately, we have not been able to reproduce this issue as well

For what it's worth, since the call site is within Rudderstack's code, is it possible to simply try-catch the exception?

1abhishekpandey commented 2 months ago

Hey @jiebo,

We were also considering catching this exception, as you mentioned, since we haven't been able to reproduce the crash on any simulator devices. We will plan to work on this fix soon.

Meanwhile can you please help us with one more info:

  1. How many total % of your events are getting affected by this crash?
jiebo commented 2 months ago

Hello, I don't think it's possible to know the percentage of events affected by this crash since we don't know how many events we will get actually get without the crash. That being said, I don't suppose it to be a huge number. However, because it occurs in the background and silently, this particular crash accounts for more than half of all our recorded crashes.

1abhishekpandey commented 1 month ago

Hey @jiebo,

We have released a fix in v1.25.1. Please try it and let us know if it successfully resolves your issue.

1abhishekpandey commented 1 month ago

Hey @jiebo, Have you had a chance to try the fix? If so, could you please let us know the results?

jiebo commented 1 month ago

Hi @1abhishekpandey, sorry for the late response. Yes, we've updated to the new version and we can confirm that the issue is resolved, please close this issue as needed. Thanks for the quick turnaround!