osmdroid: Crash when updating from 6.0.0 to 6.0.2 due to cache database locked
Issue Type
[X] Bug
Description and/or steps/code to reproduce the problem
Update your app with osmdroid 6.0.0 to osmdroid 6.0.2 with a cache database > 400 MB. On first map launch it will crash if tiles are to be downloaded immediately and written with SqlTileWriter.saveFile, because the database is locked. I take this is caused by the database index creation update in #973 ? On second launch it’s working again.
04-19 10:39:39.749 E/SQLiteDatabase: Error inserting tile=[B@cb96fbd expires=1334919638000 provider=Mapnik key=905965568
android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5)
at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:783)
at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1548)
at android.database.sqlite.SQLiteDatabase.replace(SQLiteDatabase.java:1464)
at org.osmdroid.tileprovider.modules.SqlTileWriter.saveFile(SqlTileWriter.java:150)
at org.osmdroid.tileprovider.modules.MapTileDownloader$TileLoader.loadTile(MapTileDownloader.java:255)
at org.osmdroid.tileprovider.modules.MapTileModuleProviderBase$TileLoader.run(MapTileModuleProviderBase.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
04-19 10:39:42.265 E/SQLiteDatabase: Error inserting tile=[B@5d34fd6 expires=1334880026000 provider=Mapnik key=905973758
android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5)
at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:783)
at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1548)
at android.database.sqlite.SQLiteDatabase.replace(SQLiteDatabase.java:1464)
at org.osmdroid.tileprovider.modules.SqlTileWriter.saveFile(SqlTileWriter.java:150)
at org.osmdroid.tileprovider.modules.MapTileDownloader$TileLoader.loadTile(MapTileDownloader.java:255)
at org.osmdroid.tileprovider.modules.MapTileModuleProviderBase$TileLoader.run(MapTileModuleProviderBase.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
04-19 10:39:42.578 E/AndroidRuntime: FATAL EXCEPTION: Thread-4
java.lang.NullPointerException: Attempt to invoke virtual method 'long java.io.File.length()' on a null object reference
at org.osmdroid.tileprovider.modules.SqlTileWriter.runCleanupOperation(SqlTileWriter.java:114)
at org.osmdroid.tileprovider.modules.SqlTileWriter$1.run(SqlTileWriter.java:69)
at org.osmdroid.util.GarbageCollector$1.run(GarbageCollector.java:31)
at java.lang.Thread.run(Thread.java:764)
If it’s a bug, version(s) of android this affects:
All
Version of osmdroid the issue relates to:
6.0.2
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 25 (10 by maintainers)
Commits related to this issue
- bug/#1005 - SqlTileWriter now uses a static database, in order to avoid locks A direct impact is that the app must be restarted in order to have a database path change taken into account. Impacted c... — committed to osmdroid/osmdroid by monsieurtanuki 6 years ago
- Merge pull request #1008 from osmdroid/bug/#1005 bug/#1005 - SqlTileWriter now uses a static database, in order to avoid locks — committed to osmdroid/osmdroid by monsieurtanuki 6 years ago
Didn’t read the code yet, but the problem is, that index creation may take long. Question is, if you can provide an API call to trigger early index creation. I.e. my app has a splash screen, it would be easy to trigger index creation then and would run while various other things initialize and before the map activity is launched.
@monsieurtanuki Did some tests now:
On second test I deleted updated cache.db / cache.db-journal and recopied old ones, with the result of ongoing logs of
android.database.sqlite.SQLiteReadOnlyDatabaseException: attempt to write a readonly databaseand no tiles shown. Closing the app doesn’t help, just reinstalling / rerunning from AS. I figured, that in the end we indeed need to close the DB. Tested the following inSqlTileWriter.onDetachand it seems to do the trick. Any reason, why we shouldn’t close the DB even when detaching everything else? DB seems to stay locked internally forever…