-
Notifications
You must be signed in to change notification settings - Fork 25
Connection pool closing causing app crash #15
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
Comments
upon further investigation the seems to happen something like this get a db instance from SQLiteOpenHelper.getWritableDatabase() eventually the app crashes with connection pool reference count as 0. |
Hi @zkrige, Thanks for reaching out. Are you able to reproduce the issue in a standalone application? We'd be happy to review a small public sample if you're able to. |
Hi @zkrige - were you able to reproduce this issue in a standalone sample? |
Apologies - I haven't gotten around to building a standalone app |
Sorry I seem to have some confusion. I reported the issue over here -sqlcipher/android-database-sqlcipher#628 I have since moved to using the library in this repo. I was still getting the crash in 4.5.3 of this library We upgraded to 4.5.4 and will see how new builds behave |
Hello @zkrige - have you been able to reproduce this issue under 4.5.4 or 4.5.5? |
Unfortunately still seeing this fairly consistently on 4.5.4. I haven't tested 4.5.5 yet - I will implement and see how it goes |
I'm seeing the same on 4.5.5 |
Hi @zkrige, Thank you for your report. Would it be possible to prepare a standalone sample that showcases the behavior you are experiencing? This would be helpful in diagnosing the issue. |
This definitely seems to be related to doing db work on background threads ATAL EXCEPTION: pool-33-thread-1
more specifically, it doesnt happen every time. it ONLY seems to happen if I have run db upgrades on app startup private void executeInTry(SQLiteDatabase db, String query) {
could it be something in execsql that is releasing a reference when it shouldn't? |
not sure if this is related but im seeing a LOT of The connection pool for database '/data/user/0/app/databases/encrypted.db' has been unable to grant a connection to thread 462 (pool-339-thread-1) with flags 0x1 for 30.594002 seconds. Connections: 0 active, 1 idle, 0 available. for many different threads enabling WAL seems to get rid of this, but im not sure if theres other problems that might arise |
I think this is where reference counting goes wonky. for some reason, assigning new SQLiteStatement is decreasing the db reference count public void rawExecSQL(String sql, Object...bindArgs) throws SQLException { But I think the reference is being released on another thread so basically it boils down to reference counting isnt consistent across different threads |
Hi @zkrige, @theBlbDan, Thank you for providing these details, we would like to investigate the connection pooling issue further. Can you tell us a bit more about your usage of the API so we can better understand what a recreation might entail?
|
thanks for looking at this
sorry im not able to provide more info. In our google play pre-release testing, one device consistently fails but the other 9 devices pass without any issues |
Hi @zkrige,
When this occurs, do you know if they are
Can you share what device and OS version the crash is occurring on? |
|
Hi @zkrige, thank you for the update. What devices/OS versions do you not see this issue occurring on? |
I use the 'ol singleton approach
All of my statements are executed via method calls in I use a very simple class that uses Here is an example workflow and an associated stack trace of my problematic area:
Here is a stack trace:
A similar, yet recurring trace:
Our main view is reading a chapter of the Bible where we pull in data a from one or two Bible DB's (depending if reading in parallel or if fetching this data from online), data from highlights, favorites, footnotes, & pericope DB's. I never close the databases intentionally, nor do I drop the instances from the singleton except in a restore from backup or in The user can navigate back and forth though chapters via a pair of Prev / Next arrows, so there can be quite a few fetches back to back. However, I have yet to replicate this either on any simulator or actual device. Let me know how I can further help. |
so now on google play, its stopped giving the error - all 10 devices work fine but I am seeing it in testing on my side
this specific query happens on an executor service background thread |
Hi @zkrige, @theBlbDan, I haven't been able to reproduce the behavior you are seeing with the connection pool closing. I put together an admittedly small application to generate data load via an Footnotes |
I removed the executor service and I still get the crash on main thread. In my case it was happening from a content resolver but in @theBlbDan case it seems to be happening directly on cursor queries How important is it to reference count the resources? Is there not some other way to handle auto closing? |
Ah I understand I'm seeing it on emulator as well now. |
Device(s) with issues Exceptions |
I experience these crashes with our application - not the sample app. I believe the sample app isnt complicated enough to get the reference counting to break |
just bumping this
|
Hi @zkrige, I'm sorry, we have not been able to reproduce the behavior you are seeing, even with a sample application. If you get the time to isolate the issue further into a reproduction case, we would be happy to dig into the issue further. |
I eventually figured this out. It's a race condition in a thread causing the pool to close when it should stay open. when my app starts up I spin off a thread that does an update via rawExecSQL. this opens the first db connection in a thread. when this completes it closes the pool BUT while this is happening, there is another thread that spins up and does normal select queries. the first statement closes the pool while the thread for the select query is active by the time the select query tries to actually query, the pool is closed and the exception happens. I fixed it by making the 2nd action wait for the first one to complete |
Hi @zkrige, Thank you for providing an update! We're happy to hear you were able to isolated the issue within your application. |
java.lang.RuntimeException: An error occurred while executing doInBackground()
at androidx.loader.content.ModernAsyncTask$3.done(ModernAsyncTask.java:164)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
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:920)
Caused by: java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.
at net.zetetic.database.sqlcipher.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:973)
at net.zetetic.database.sqlcipher.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:688)
at net.zetetic.database.sqlcipher.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:359)
at net.zetetic.database.sqlcipher.SQLiteSession.acquireConnection(SQLiteSession.java:929)
at net.zetetic.database.sqlcipher.SQLiteSession.executeForCursorWindow(SQLiteSession.java:869)
at net.zetetic.database.sqlcipher.SQLiteQuery.fillWindow(SQLiteQuery.java:66)
at net.zetetic.database.sqlcipher.SQLiteCursor.fillWindow(SQLiteCursor.java:196)
at net.zetetic.database.sqlcipher.SQLiteCursor.getCount(SQLiteCursor.java:135)
at android.content.ContentResolver.query(ContentResolver.java:1238)
at android.content.ContentResolver.query(ContentResolver.java:1151)
The text was updated successfully, but these errors were encountered: