djp952 / pvr.hdhomerundvr

Unofficial Kodi HDHomeRun DVR PVR Client
https://github.com/djp952/pvr.hdhomerundvr/wiki
Other
60 stars 9 forks source link

Error being logged by Android: database is locked #4

Closed djp952 closed 7 years ago

djp952 commented 7 years ago

Android Jarvis (x86) is logging the "database is locked" error in GetChannels (pvr.cpp). Not sure if this is a defect in the Jarvis baseline or specific to android/android-x86 yet. Need to investigate, if the problem is something systemic with the updated SQLite (3.17.0) it will cause users an unending amount of annoying problems.

djp952 commented 7 years ago

So far this appears to be a performance issue on the Android emulators only, but I only have one physical Android device to test on. I also see "disk I/O" errors on the emulator which lead to the same result - database queries that fail. This makes more sense than "database is locked" anyway -- SQLite is using WAL mode, which uses a secondary transaction log file. The solution on Android may be to implement a retry mechanism, but I would prefer to find the root cause why this happens first; I would expect SQLite to handle the slow storage better than it seems to.

djp952 commented 7 years ago

Root cause appears to have been the introduction of a connection pool for the SQLite database without cleaning up the steps and order of operations used when opening a new connection. Database schema and static table data were being reinitialized unnecessarily but more importantly ensuring that the database is set for WAL and setting up the busy handler was being done after these initialization tasks. These changes appear to have resolved the problem.