Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Locked database errors #63

Closed
kegsay opened this issue Sep 8, 2016 · 1 comment
Closed

Locked database errors #63

kegsay opened this issue Sep 8, 2016 · 1 comment
Labels

Comments

@kegsay
Copy link
Member

kegsay commented Sep 8, 2016

{
  "error":"database is locked",
  "level":"error",
  "msg":"Failed to persist next_batch token",
  "next_batch":"s39513903_25872915_34252_3708100_14886_10006_12",
  "time":"2016-09-08T09:06:24+01:00",
  "user_id":"@neb_giphy:matrix.org"
}
@kegsay kegsay added the bug label Sep 8, 2016
@kegsay
Copy link
Member Author

kegsay commented Oct 13, 2016

mattn/go-sqlite3#274

sqlite allows multiple readers but only a single writer at any one time. If you have multiple connections to the same DB, you will inevitably run into database is locked. This is an unavoidable consequence of sqlite's locking model, and therefore something your application needs to deal with. Possible solutions include:

  • Only ever open a single connection to the DB (but note this can still result in multiple connections to the DB if a user runs multiple instances of your application at once)
  • Set the busy timeout to something reasonably high (which causes sqlite to retry lock acquisition for a certain amount of time before returning database is locked). In go-sqlite3 this is achieved by appending eg. ?_busy_timeout=5000 to the filename passed to sql.Open, where 5000 is the number of milliseconds to retry.
    Also note that tx.Begin() and tx.Commit() are currently affected by issue Create a gitlab bot #184 which can result in a connection getting stuck in an inconsistent state if SQLITE_BUSY is encountered while commit is in progress. But setting an appropriate busy timeout should avoid this situation also (unless you have excessively long lived transactions in which case you might want to rethink your design and/or ensure that you're closing all your transaction/result objects in a timely manner).

Yay?

kegsay added a commit that referenced this issue Oct 13, 2016
Edit README to put `_busy_timeout` to fix database is locked errors (#63)
@kegsay kegsay closed this as completed Oct 13, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant