Skip to content

Is it necessary to close the database connnection explicitly and how #344

Closed

Description

@Betristor

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?

Activity

  1. quinnj commented on Sep 30, 2026

    @quinnj
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions