Wait on a busy SQLite database and turn on WAL mode (closes #198)
check / check (push) Failing after 2s

Requests and the eviction pass write on separate connections, and with
no busy timeout a write that met another one failed at once with
"database is locked" and was lost. internal/database now adds
_pragma=busy_timeout(5000) to every db_url, the default or one the
operator sets, so such a write waits up to five seconds. The default
db_url's _journal_mode=WAL is not a parameter the driver reads, so it
is now _pragma=journal_mode(WAL). README.md and config.example.yml say
what pixa adds to db_url.

Model: opus-5-5
This commit was merged in pull request #200.
This commit is contained in:
2026-10-04 20:58:37 +02:00
parent 66e71b4207
commit 625fd42ace
7 changed files with 217 additions and 6 deletions
+11 -1
View File
@@ -243,7 +243,17 @@ func (s *Database) DB() *sql.DB {
}
func (s *Database) connect(ctx context.Context) error {
dbURL := s.config.DBURL
// Requests and the eviction pass write on separate connections. With
// a busy timeout, a write that finds another one in progress waits up
// to five seconds for it instead of failing at once with "database is
// locked". The driver runs each _pragma parameter on every connection
// it opens.
separator := "?"
if strings.Contains(s.config.DBURL, "?") {
separator = "&"
}
dbURL := s.config.DBURL + separator + "_pragma=busy_timeout(5000)"
s.log.Info("connecting to database", "url", dbURL)