Reputation: 5301
We've been having some trouble with Android's Room database lately.
The crashes happen only to certain users, but I cannot reproduce it on my testing device(s) or emulators. (This also happens SOMETIMES on Firebase test devices)
There are a few exceptions which all seem to be related.
All these exceptions are happening in different lines of our Dao, which is generated by Room.
(Be it a query, insert, update or delete).
CursorWindowAllocationException: Cursor window allocation of 2048 kb failed.
IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: ‘/whatever/database’
SQLiteDiskIOException: disk I/O error (code 266)
SQLiteDiskIOException: disk I/O error (code 778)
SQLiteDatabaseCorruptException: file is encrypted or is not a database (code 26)
SQLiteException: Failed to change locale for db ‘/whatever/database' to 'fr_FR'.
What I've tried:
None of these methods helped, and the bug is still there.
The LiveData's query is the only one which is NOT offloaded the default database Executor, as I couldn't find a way to do that. I suspect this might be the issue, but I'm not entirely sure.
This is the LiveData query
@Query("SELECT * FROM alarms WHERE deleted =0 ORDER BY isActive DESC, hourOfDay, minuteOfHour")
LiveData<List<Alarm>> getLiveAlarmList();
exception examples:
Fatal Exception: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed.
at android.database.CursorWindow.(CursorWindow.java:108)
at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
at android.database.sqlite.SQLiteCursor.clearOrCreateWindow(SQLiteCursor.java:300)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:138)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:132)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:219)
at android.database.AbstractCursor.moveToNext(AbstractCursor.java:268)
at android.arch.persistence.room.InvalidationTracker$1.checkUpdatedTable(SourceFile:358)
at android.arch.persistence.room.InvalidationTracker$1.run(SourceFile:329)
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:762)
This one appears to originate form Room's LiveData InvalidationTracker class.
Fatal Exception: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=1 (# cursors opened by this proc=1)
at android.database.CursorWindow.(CursorWindow.java:108)
at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:225)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:149)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:143)
at com.sofaking.moonworshipper.database.room.AlarmDao_Impl.getAllAlarms(SourceFile:458)
at com.sofaking.moonworshipper.database.AlarmHelper.getAllAlarms(SourceFile:29)
at com.sofaking.moonworshipper.registration.DefaultAlarmRegistrationImpl.onCancelPendingAlarms(SourceFile:36)
at com.sofaking.moonworshipper.registration.BaseAlarmRegistrationImpl$start$runnable$1.run(SourceFile:26)
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:761)
While this one comes from a service that querys for "all alarms". Notice that 'AlarmDao_Impl.getAllAlarms' is generated by Room, and does indeed close the cursor when it's done.
Fatal Exception: android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 266)
at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:1015)
at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:836)
at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:147)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:136)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:197)
at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:237)
at android.arch.persistence.room.RoomOpenHelper.checkIdentity(SourceFile:127)
at android.arch.persistence.room.RoomOpenHelper.onOpen(SourceFile:115)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onOpen(SourceFile:151)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:266)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(SourceFile:96)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(SourceFile:54)
at android.arch.persistence.room.RoomDatabase.query(SourceFile:233)
at com.sofaking.moonworshipper.database.room.AlarmDao_Impl$4.compute(SourceFile:555)
at com.sofaking.moonworshipper.database.room.AlarmDao_Impl$4.compute(SourceFile:541)
at android.arch.lifecycle.ComputableLiveData$2.run(SourceFile:100)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Another LiveData query crash.
Fatal Exception: android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 778)
at android.database.sqlite.SQLiteConnection.nativeExecute(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:561)
at android.database.sqlite.SQLiteSession.endTransactionUnchecked(SQLiteSession.java:437)
at android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:401)
at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:528)
at android.arch.persistence.db.framework.FrameworkSQLiteDatabase.endTransaction(SourceFile:90)
at android.arch.persistence.room.RoomDatabase.endTransaction(SourceFile:261)
at com.sofaking.moonworshipper.database.room.AlarmDao_Impl.update(SourceFile:188)
at com.sofaking.moonworshipper.registration.DefaultAlarmRegistrationImpl.onCalculateAlarms(SourceFile:58)
at com.sofaking.moonworshipper.registration.BaseAlarmRegistrationImpl$start$runnable$1.run(SourceFile:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
This comes from updating the the object instance (also handled by Room)
Fatal Exception: android.database.sqlite.SQLiteDatabaseCorruptException: file is encrypted or is not a database (code 26)
at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:845)
at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:836)
at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:143)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:132)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:219)
at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:258)
at android.arch.persistence.room.RoomOpenHelper.hasRoomMasterTable(SourceFile:155)
at android.arch.persistence.room.RoomOpenHelper.checkIdentity(SourceFile:123)
at android.arch.persistence.room.RoomOpenHelper.onOpen(SourceFile:115)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onOpen(SourceFile:151)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:266)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(SourceFile:96)
at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(SourceFile:54)
at android.arch.persistence.room.RoomDatabase.query(SourceFile:233)
at com.sofaking.moonworshipper.database.room.AlarmDao_Impl$4.compute(SourceFile:321)
at com.sofaking.moonworshipper.database.room.AlarmDao_Impl$4.compute(SourceFile:307)
at android.arch.lifecycle.ComputableLiveData$2.run(SourceFile:100)
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:761)
Again, seems to be coming from LiveData's AlarmDao_Impl$4.compute() method
Fatal Exception: android.database.sqlite.SQLiteException: Failed to change locale for db '/data/user_de/0/com.sofaking.moonworshipper/databases/alarm-database' to 'fr_FR'.
at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:402)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:223)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:198)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.tryAcquireNonPrimaryConnectionLocked(SQLiteConnectionPool.java:899)
at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:609)
at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:348)
at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:586)
at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1353)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1328)
at android.arch.persistence.db.framework.FrameworkSQLiteDatabase.query(SourceFile:161)
at android.arch.persistence.room.RoomDatabase.query(SourceFile:233)
at com.sofaking.moonworshipper.database.room.AlarmDao_Impl.getAllAlarms(SourceFile:438)
at com.sofaking.moonworshipper.database.AlarmHelper.getAllAlarms(SourceFile:29)
at com.sofaking.moonworshipper.registration.DefaultAlarmRegistrationImpl.onCancelPendingAlarms(SourceFile:36)
at com.sofaking.moonworshipper.registration.BaseAlarmRegistrationImpl$start$runnable$1.run(SourceFile:26)
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:761)
Same area as the second CursorWindowAllocationException, but with a different crash
Upvotes: 5
Views: 7238
Reputation: 5301
In the end, the errors had nothing to do with the database itself. I had some image assets that were not resized to MDPI, HDPI, or XHDPI. They were only supplied in XXHDPI.
To quote this answer from another thread: https://stackoverflow.com/a/25861292/8198740
If you look up the source of CursorWindowAllocationException
it reads:
This exception is thrown when a CursorWindow couldn't be allocated, most probably due to memory not being available.
So apparently, because the images were taking up so much of the app's heap memory, the cursor couldn't allocate itself.
Now I have none of those crashes.
Upvotes: 3