Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repetitive crashes on 4.5.3: net.sqlcipher.CursorWindow.<init> & native_init #618

Open
cokeperez opened this issue Mar 17, 2023 · 2 comments

Comments

@cokeperez
Copy link

A few weeks ago we upgraded the version of SQLCipher in our application from 4.5.1 to 4.5.3. Since we updated the SQLCipher version, we are receiving dozens of crashes related to cursors on a daily basis.

Some info about the problem:

  • Queries and related code have not been modified for years.
  • The cursors are initialized and closed correctly on every query.
  • The crashes occur on different queries and in random situations.
  • In general, queries are simple, projecting a few columns and one or a few rows.
  • We have not been able to reproduce it.
  • We have used previous versions of SQLiteCipher for several years with the same code and barely 5-10 such crashes came in several months.

The two crashes that happen are:

net.sqlcipher.CursorWindow.<init> (two different causes)

85% on Android 4 (although this version only accounts for 20% of our network). These users on API19 (Android 4.4.2 and 4.4.4.4) all have older Samsung devices (Galaxy Tab 3/4/E). The remaining 15% are split between Android 9, 10 and 11, so the problem is not unique to Android 4 but does seem to be more prevalent on this version.

Caused by 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.CursorWindow.<init>(CursorWindow.java:131)
       at net.sqlcipher.CursorWindow.<init>(CursorWindow.java:67)
       at net.sqlcipher.database.SQLiteCursor.fillWindow(SQLiteCursor.java:301)
       at net.sqlcipher.database.SQLiteCursor.getCount(SQLiteCursor.java:292)
       at net.sqlcipher.AbstractCursor.moveToPosition(AbstractCursor.java:178)
       at net.sqlcipher.AbstractCursor.moveToFirst(AbstractCursor.java:222)
       at android.database.CursorWrapper.moveToFirst(CursorWrapper.java:65)
       at org.frogtek.database.wrapper.Cursor.moveToFirst(Cursor.java:50)
       ...
       ...
Caused by android.database.CursorWindowAllocationException: Could not allocate CursorWindow '<unnamed>' of size 2097152 due to error -12.
       at android.database.CursorWindow.nativeCreate(CursorWindow.java)
       at android.database.CursorWindow.<init>(CursorWindow.java:139)
       at android.database.CursorWindow.<init>(CursorWindow.java:120)
       at android.database.CursorWindow.<init>(CursorWindow.java:162)
       at net.sqlcipher.CursorWindow.<init>(CursorWindow.java:67)
       at net.sqlcipher.database.SQLiteCursor.fillWindow(SQLiteCursor.java:301)
       at net.sqlcipher.database.SQLiteCursor.getCount(SQLiteCursor.java:292)
       at net.sqlcipher.AbstractCursor.moveToPosition(AbstractCursor.java:178)
       at net.sqlcipher.AbstractCursor.moveToFirst(AbstractCursor.java:222)
       at android.database.CursorWrapper.moveToFirst(CursorWrapper.java:75)
       ...
       ...

net.sqlcipher.CursorWindow.native_init

99% on Android 4

Fatal Exception: java.lang.IllegalStateException: Couldn't init cursor window
       at net.sqlcipher.CursorWindow.native_init(CursorWindow.java)
       at net.sqlcipher.CursorWindow.<init>(CursorWindow.java:72)
       at net.sqlcipher.database.SQLiteCursor.fillWindow(SQLiteCursor.java:301)
       at net.sqlcipher.database.SQLiteCursor.getCount(SQLiteCursor.java:292)
       at net.sqlcipher.AbstractCursor.moveToPosition(AbstractCursor.java:178)
       at net.sqlcipher.AbstractCursor.moveToFirst(AbstractCursor.java:222)
       at android.database.CursorWrapper.moveToFirst(CursorWrapper.java:65)
       ...
       ...

We have released a new version of our app by downgrading the SQLiteCipher version and the crashes have stopped.

What do you think could be happening, any idea how to solve it?

Thanks a lot for your help!

@developernotes
Copy link
Member

Hi @cokeperez,

In terms of the changes directly within SQLCipher for Android between 4.5.1 and 4.5.3, those may be found here along with the SQLCipher core changes here changes. Given the changes it is particularly strange that reverting to 4.5.1 resolved the errors.

We have not been able to reproduce it.

Do you have the same devices in order to attempt to reproduce this error?

Based on the error message, it appears the library is failing to allocate additional memory on those specific devices when returning the cursor. If you are not customizing the cursor window allocation, you would be using the default configuration. You can customize this for your application, a few examples may be found here and here. It is worth investigating whether an adjustment to the allocation improves the behavior of the application.

@cokeperez
Copy link
Author

Thank you for your response @developernotes.

We have the same devices and have access to full copies of the user databases, but even so we have not been able to reproduce it. Our app is a point of sale that is usually running more than 12 hours a day on the devices so it is complicated to replicate exactly the same conditions of the users. The same query that causes a user to crash is executed hundreds of times during the day without problems, with the user repeating the same flow of activities.

This week I will try running the tests you link me to on the devices that are failing, to see if we can reproduce it. I also check out the option to customize the cursor window allocation and generate a test version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants