mwild1 / luadbi

Multi-backend SQL database library for Lua
MIT License
41 stars 15 forks source link

missing locks on SQLite3 DB file and WAL shm file #37

Closed woffs closed 7 years ago

woffs commented 8 years ago

With luadbi and SQLite3 and pragma journal_mode=wal, there is no lock set on the DB file and the -shm file. Other processes using non-lua libraries accessing the DB do not notice that the DB is still in use and remove the WAL related files, leading to possible DB corruption or data loss. I experienced this running prosody-trunk on Debian Jessie.

With the non-lua sqlite3 commandline client, with pragma journal_mode=wal, the sqlite DB file (and the wal related -shm file) are locked with a read lock. When concurrent processes access the same DB, the temporary -wal and -shm files are remove not earlier than the last client removed its lock.

woffs commented 7 years ago

https://prosody.im/issues/issue/784

sparked435 commented 7 years ago

I'm having trouble wrapping my head around this particular problem. There doesn't seem to be any mention in any Sqlite3 documentation that an application needs to maintain any sort of locking that isn't already done by Sqlite3 itself.

Of course, this doesn't mean there is not an issue in LuaDBI. I just can't find a way to reproduce the problem.

Is there a way to recreate the problem, preferably via a short script?

sparked435 commented 7 years ago

Please try version 0.6 and reopen if the problem still occurs.