You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is it necessary to close the database connnection explicitly and how #344
I'm using SQLite to record results from repeated optimization results. Each run a result will be appended to the database file but sometimes results are dropped and no error occurred when parallel processes go on. I enabled the WAL mode of SQLite to avoid locked database error but still some results are missing for random. I was suggested to close the database connection in each thread but there is no description about the close function. Now I'm curious about the close action and when and how to do it. Is there any paradigm to follow?
Yes: close each connection explicitly with close(db) when you're done, ideally in try/finally (docs updated in #359). The next release also fixes a case where abandoned statements weren't finished by close(db) and could hold locks or commit later (#362). With several processes writing, also check every write's result: an SQLITE_BUSY error means a write didn't happen, so use a busy timeout and retry. Please reopen with a small reproduction if results still go missing after that.
Activity
quinnj commentedon Sep 30, 2026
Yes: close each connection explicitly with
close(db)when you're done, ideally intry/finally(docs updated in #359). The next release also fixes a case where abandoned statements weren't finished byclose(db)and could hold locks or commit later (#362). With several processes writing, also check every write's result: anSQLITE_BUSYerror means a write didn't happen, so use a busy timeout and retry. Please reopen with a small reproduction if results still go missing after that.