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

SQLiteOpenHelper concurrent creation crash #2360

Closed
pyricau opened this issue Apr 17, 2022 · 1 comment · Fixed by #2361
Closed

SQLiteOpenHelper concurrent creation crash #2360

pyricau opened this issue Apr 17, 2022 · 1 comment · Fixed by #2361
Milestone

Comments

@pyricau
Copy link
Member

pyricau commented Apr 17, 2022

This occurred in CI on API 16 in #2358

E/SQLiteLog( 2716): (1) table heap_analysis already exists
W/dalvikvm( 2716): threadid=19: thread exiting with uncaught exception (group=0xb113b228)
E/AndroidRuntime( 2716): FATAL EXCEPTION: HeapAnalyzer
E/AndroidRuntime( 2716): android.database.sqlite.SQLiteException: table heap_analysis already exists (code 1)
E/AndroidRuntime( 2716): 	at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method)
E/AndroidRuntime( 2716): 	at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:727)
E/AndroidRuntime( 2716): 	at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754)
E/AndroidRuntime( 2716): 	at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64)
E/AndroidRuntime( 2716): 	at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1665)
E/AndroidRuntime( 2716): 	at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
E/AndroidRuntime( 2716): 	at leakcanary.internal.activity.db.LeaksDbHelper.onCreate(LeaksDbHelper.kt:18)
E/AndroidRuntime( 2716): 	at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
E/AndroidRuntime( 2716): 	at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
E/AndroidRuntime( 2716): 	at leakcanary.internal.AndroidDebugHeapAnalyzer.runAnalysisBlocking(AndroidDebugHeapAnalyzer.kt:93)
E/AndroidRuntime( 2716): 	at leakcanary.internal.AndroidDebugHeapAnalyzer.runAnalysisBlocking$default(AndroidDebugHeapAnalyzer.kt:46)
E/AndroidRuntime( 2716): 	at leakcanary.BackgroundThreadHeapAnalyzer$onEvent$1.run(BackgroundThreadHeapAnalyzer.kt:24)
E/AndroidRuntime( 2716): 	at android.os.Handler.handleCallback(Handler.java:615)
E/AndroidRuntime( 2716): 	at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 2716): 	at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 2716): 	at android.os.HandlerThread.run(HandlerThread.java:60)

This seems to be related to this: https://stackoverflow.com/a/26127930

Sounds we need to have a singleton LeaksDbHelper instance, however I don't know when we should close it.

@pyricau
Copy link
Member Author

pyricau commented Apr 17, 2022

General guidance:

  • Make LeaksDbHelper a singleton
  • Hide it away / wrap it
  • Under the hood have a system for counting concurrent opens and only close the db when down to 0
  • Offer operations to borrow and return db.
  • Offer an operation for single shot usages, open + close (decrease count) db

pyricau added a commit that referenced this issue Apr 18, 2022
@pyricau pyricau added this to the 2.9 milestone Apr 18, 2022
pyricau added a commit that referenced this issue Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant