Baseflow / flutter_cache_manager

Generic cache manager for flutter
https://baseflow.com
MIT License
739 stars 426 forks source link

Database locked #312

Closed vishnukvmd closed 3 years ago

vishnukvmd commented 3 years ago

Firstly, thanks for the great library. It is very well architected.

🐛 Bug Report

I see a flurry of the following logs intermittently:

Warning database has been locked for 0:00:10.000000. Make sure you always use the transaction object for database operations during a transaction
Warning database has been locked for 0:00:10.000000. Make sure you always use the transaction object for database operations during a transaction
Warning database has been locked for 0:00:10.000000. Make sure you always use the transaction object for database operations during a transaction
Warning database has been locked for 0:00:10.000000. Make sure you always use the transaction object for database operations during a transaction
Warning database has been locked for 0:00:10.000000. Make sure you always use the transaction object for database operations during a transaction
...

Upon enabling the debug mode with Sqflite.devSetDebugModeOn(true), I can see that this is triggered during an UPDATE query that looks as follows:

[5,Sqflite(1651)] UPDATE cacheObject SET url = ?, key = ?, relativePath = ?, eTag = ?, validTill = ?, touched = ?, length = NULL, _id = ? WHERE _id = ? [https://api.ente.io/files/preview/93180, https://api.ente.io/files/preview/93180, 67fb5c60-
                            acfa-11eb-8eb9-a3b77d1e7ce6.file, https://api.ente.io/files/preview/93180, 1651683705126, 1620333756544, 1124, 1124]

This is a race condition that happens intermittently but cannot be reproduced reliably.

Further inspection makes me question the complexity of the current code that ensures a single instance of DB.

It might make sense to use a simpler approach as recommended by the author of the sqflite library: https://github.com/tekartik/sqflite/blob/master/sqflite/doc/usage_recommendations.md#single-database-connection.

Please let me know if I can help.

Thanks again!

renefloor commented 3 years ago

Thanks for the research. I copied your report to here as there is already an issue about this #204