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

java.lang.IllegalStateException: database /data/user/0/<app>/databases/<app>_encrypted.db already closed #628

Closed
zkrige opened this issue Jun 3, 2023 · 7 comments

Comments

@zkrige
Copy link

zkrige commented Jun 3, 2023

Expected Behavior

DB stays open

Actual Behavior

DB is being closed at some point

at net.sqlcipher.database.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:57)
at net.sqlcipher.database.SQLiteProgram.<init>(SQLiteProgram.java:91)
at net.sqlcipher.database.SQLiteQuery.<init>(SQLiteQuery.java:50)
at net.sqlcipher.database.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:60)
at net.sqlcipher.database.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:2019)
at net.sqlcipher.database.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1802)
at net.sqlcipher.database.SQLiteDatabase.query(SQLiteDatabase.java:1754)
at net.sqlcipher.database.SQLiteDatabase.query(SQLiteDatabase.java:1886)

Steps to Reproduce

....
SQLCipher version (can be identified by executing PRAGMA cipher_version;):
4.54 community

SQLCipher for Android version:
4.54

Are you able to reproduce this issue within the SQLCipher for Android test suite?
No

The db seems to behave for a while, and then at some point, it gets closed. I have multiple reads and writes happening from different background tasks.

This is an existing app that was using standard android sqlite. I've just done a drop in replacement for the sqlcipher version. If I revert to standard android sqlite, it works fine

@sjlombardo
Copy link
Member

There is not enough information here to determine what the problem is. Are all of the threads you mentioned sharing a single database connection? Or does each thread have it's own separate connection? Have you determined if there are any exceptions being thrown that might be causing one of your application's threads to close the database connection prematurely?

@zkrige
Copy link
Author

zkrige commented Jul 18, 2023

Im having a hard time creating a test app that reproduces this, but im definitely seeing quite a bit of it in our production app

@zkrige
Copy link
Author

zkrige commented Jul 18, 2023

here's a screenshot from crashlytics showing a bunch of crashes in our prod app

image

@sjlombardo
Copy link
Member

Hello @zkrige - I definitely believe the problem is occurring for you. However, screenshots of Crashlytics don't provide any useable information. Can you please answer the questions earlier in this thread? It is possible that it is a bug, but it is much more likely that somehow one of your threads is closing the database handle unexpectedly. I would really recommend checking any logic related to closing database connections.

@zkrige
Copy link
Author

zkrige commented Jul 18, 2023

We don't have any calls to close db connections. The DB is provided via a singleton that gets instantiated early on in app lifecycle. It is never closed or released.

preliminary testing points to something in the query component going awry but I can't seem to pin down the exact scenario causing it. The reference count is at some point decremented once too many and the library then thinks the db is closed

@zkrige
Copy link
Author

zkrige commented Jul 19, 2023

I'm not using this library anymore - have moved to https://github.com/sqlcipher/sqlcipher-android/ - will monitor and see if it continues

@sjlombardo
Copy link
Member

Closing as logged against the wrong library, discussion moved to referenced ticket.

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