From b24c419ceb0cfb37d844f5b764faeb8cc5f54bac Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Sun, 9 Aug 2026 18:16:30 +0200 Subject: [PATCH] fix db lock #1209 --- database/db.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/database/db.go b/database/db.go index ce9b3e9..01eb006 100644 --- a/database/db.go +++ b/database/db.go @@ -59,7 +59,11 @@ func OpenDB(dbPath string) error { // _cache_size=-200 caps each connection's page cache at ~200 KiB // (default is ~2 MiB), reducing memory amplification if a connection // escapes the pool. - dsn := dbPath + sep + "_busy_timeout=10000&_journal_mode=WAL&_cache_size=-200" + // _txlock=immediate makes transactions take the write lock up front. + // Deferred transactions that read first and then write (e.g. the deplete + // job) cannot wait on the lock upgrade and fail instantly with "database + // is locked" whenever another writer (stats job) is active (#1209). + dsn := dbPath + sep + "_busy_timeout=10000&_journal_mode=WAL&_cache_size=-200&_txlock=immediate" db, err = gorm.Open(sqlite.Open(dsn), c) if err != nil { return err