urbanairship / android-library

Urban Airship Android SDK
Other
109 stars 123 forks source link

Fatal Exception: android.database.CursorWindowAllocationException #223

Closed CrispBull closed 1 year ago

CrispBull commented 1 year ago

What Airship dependencies are you using?

I am currently using only the "com.urbanairship.android:urbanairship-fcm:16.7.5" dependency

Report

A large number of my users are having this crash;

Fatal Exception: android.database.CursorWindowAllocationException: Could not allocate CursorWindow '/data/user/0/com.personally.android/no_backup/com.urbanairship.databases/5XGFwXncTkmlPa3C2qgnIw_ua_preferences.db' of size 4194304 due to error -12.
       at android.database.CursorWindow.nativeCreate(CursorWindow.java)
       at android.database.CursorWindow.<init>(CursorWindow.java:145)
       at android.database.sqlite.SQLiteCursor.clearOrCreateWindow(SQLiteCursor.java:319)
       at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:159)
       at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:152)
       at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:232)
       at android.database.AbstractCursor.moveToNext(AbstractCursor.java:281)
       at androidx.room.InvalidationTracker$1.checkUpdatedTable(InvalidationTracker.java:463)
       at androidx.room.InvalidationTracker$1.run(InvalidationTracker.java:433)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:919)
       ...
       at sun.misc.Unsafe.park(Unsafe.java)
       at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:230)
       at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:461)
       at java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:362)
       at java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:937)
       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1091)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at com.urbanairship.util.AirshipThreadFactory$1.run(AirshipThreadFactory.java:50)
       at java.lang.Thread.run(Thread.java:919)

Any reason why this is and how I can fix it please?

jyaganeh commented 1 year ago

Hi @CrispBull, I'm looking into this, but haven't found anything conclusive yet. The stack trace appears to be similar to this issue in the Android Public Tracker, though.

Would you be able to provide the output of ./gradlew dependencies?

Also, is there any info that stands out in your crash reports? I'm wondering if there are any patterns in the impacted devices, android versions, background vs foreground, etc.

Another thing that would be helpful to know is whether you're seeing any CursorWindowAllocationException reports that have different stack traces from the one you provided. It looks like the crash is originating in Room's InvalidationTracker class, and I'm curious if it's always the same db or not.

abualgait commented 1 year ago

This is happeing with me as well and it happens frequently effecting users, this is mostly happening in background, OS version: android 10, Model: Galaxy Tab A 8.0.

Fatal Exception: android.database.CursorWindowAllocationException
Could not allocate CursorWindow '/data/user/0/.../no_backup/androidx.work.workdb' of size 4194304 due to error -12.

       at android.database.CursorWindow.nativeCreate(CursorWindow.java)
       at android.database.CursorWindow.<init>(CursorWindow.java:145)
       at android.database.sqlite.SQLiteCursor.clearOrCreateWindow(SQLiteCursor.java:319)
       at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:159)
       at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:152)
       at androidx.work.impl.model.WorkTagDao_Impl.getTagsForWorkSpecId(WorkTagDao_Impl.java:133)
       at androidx.work.impl.Processor.lambda$startWork$0$androidx-work-impl-Processor(Processor.java:123)
       at androidx.work.impl.Processor$$ExternalSyntheticLambda0.call(:6)
       at androidx.room.RoomDatabase.runInTransaction(RoomDatabase.kt:603)
       at androidx.work.impl.Processor.startWork(Processor.java:121)
       at androidx.work.impl.utils.StartWorkRunnable.run(StartWorkRunnable.java:49)
       at androidx.work.impl.utils.SerialExecutorImpl$Task.run(SerialExecutorImpl.java:96)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:919)
UrbanAirship#87:
       at sun.misc.Unsafe.park(Unsafe.java)
       at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:230)
       at java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:461)
       at java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:362)
       at java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:937)
       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1091)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at com.urbanairship.util.AirshipThreadFactory$1.run(AirshipThreadFactory.java:50)
       at java.lang.Thread.run(Thread.java:919)

any reason why we get this error and how to fix that? is there any workaround that we can do until we have a fix for this?

I use this dependency: implementation "com.urbanairship.android:urbanairship-fcm:16.7.5"

jyaganeh commented 1 year ago

Hi @abualgait, as far as I can tell, both of these crashes are the same as what has been reported in Google's IssueTracker and are seemingly caused by something in Room or WorkManager.

The only actionable thing I've found so far is that the issue could be caused or made worst by missing calls to cursor.close(). I've started going through our usages of Cursor objects to make sure we're closing them all, and have not found any unclosed so far. If your app makes use of Room, it may be worth looking over your Cursor usages in case that helps. Otherwise, I unfortunately don't think there's much we can do aside from waiting for Google to fix the problem.

Out of curiosity, what version of the Airship SDK are you using? Also, what versions of Room and WorkManager is Gradle resolving in your project? You can figure that out by running the following commands:

./gradlew dependencyInsight --configuration releaseRuntimeClasspath --dependency androidx.room:room-runtime
./gradlew dependencyInsight --configuration releaseRuntimeClasspath --dependency androidx.work:work-runtime
jyaganeh commented 1 year ago

Closing this due to inactivity. Please reopen if there are any more details to share.