Search code examples
databasesqlitetagsmutexrel

Possible issues with sqlite3_mutex_enter(v->db->mutex) on cocoa c


I have an issue with the sqlite3_mutex_enter(v->db->mutex) error message on an iOS application. The case is the following: I developed an application that is performing a sync on the application in the background while starting up. All SQL Statements that invoke writing to the DB are protected using a NSLOCK and are unlocked after the finalize. Now the problem is, that the Application User can start working with the application while the sync is still ongoing. Sometimes I do get now an sqlite3_mutex_enter(v->db->mutex) when something is done on the DB level, sometimes it simply works. The cases where this error appears is mainly in read statements.

Do you have any ideas when the sqlite3_mutex_enter(v->db->mutex) error can show up? All statements are finalized properly. Something really weird is, that the SQLITE DB tries to close itself even if there is no command that tells the DB connection to close.


Solution

  • The statement sqlite3_mutex_enter(v->db->mutex) occurs only inside sqlite3_reset. An error in this place is likely to be caused by an invalid statement pointer, probably one that is already finalized.