MikhailKrishtop
MikhailKrishtop

Reputation: 542

Cursor window allocation of 2048 kb failed with rxjava adapter on room

I'm using Room with RxJava2 version 1.0.0 in my app. Previously I was using Realm and all was fine. Now when I've migrated on Room I get random rare crashes with similar stacktrace:

Fatal Exception: android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. 
       at android.database.CursorWindow.<init>(CursorWindow.java:109)
       at android.database.CursorWindow.<init>(CursorWindow.java:100)
       at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
       at android.database.sqlite.SQLiteCursor.clearOrCreateWindow(SQLiteCursor.java:301)
       at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:139)
       at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
       at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:197)
       at android.database.AbstractCursor.moveToNext(AbstractCursor.java:245)
       at android.arch.persistence.room.InvalidationTracker.run(InvalidationTracker.java:372)
       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:841)

Some times its even don't have room mentions in there. I'm not using any Cursors directly, only thru Room and 3rd party libraries (which I haven't changed during migration).

I've checked Room generated code and it all seems to close Cursors properly.

Any thoughts on what is going on and how I can debug this crashes?

Upvotes: 4

Views: 1741

Answers (1)

MikhailKrishtop
MikhailKrishtop

Reputation: 542

It turns out that the problem was in RxJava's .subscribeOn(Schedulers.io()) for Flowable responses in RxJava Room adapter. Apparently it was starting threads but has never released them. I've swapped Schedulers.io() on fixed thread pool with up to 20 threads and it does go away.

Upvotes: 1

Related Questions