From 45565fa34f4299469d3fa8c55f1325c64fe4061a Mon Sep 17 00:00:00 2001 From: Alexandr Stelnykovych Date: Fri, 30 May 2025 13:14:55 +0300 Subject: [PATCH] fix(sqlite): Limit concurrent writes to avoid SQLITE_BUSY errors https://github.com/safing/portmaster/issues/1848 (cherry picked from commit e5715a9550193653142b2b465fcb10b3d710e376) --- base/database/storage/sqlite/sqlite.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/base/database/storage/sqlite/sqlite.go b/base/database/storage/sqlite/sqlite.go index fcf52a6f..fe5427ff 100644 --- a/base/database/storage/sqlite/sqlite.go +++ b/base/database/storage/sqlite/sqlite.go @@ -89,6 +89,14 @@ func openSQLite(name, location string, printStmts bool) (*SQLite, error) { } } + // Limit concurrent writes to avoid "SQLITE_BUSY" errors on large workloads. + // SQLite typically allows only one writer at a time anyway. + // In WAL mode, concurrent readers can still function, + // but we keep a single writer to reduce lock contention. + db.SetMaxOpenConns(1) // Only 1 open connection can be active + db.SetMaxIdleConns(1) // Maintain at most 1 idle connection in the pool + db.SetConnMaxLifetime(0) // Keep the single connection alive indefinitely + // Run migrations on database. n, err := migrate.Exec(db, "sqlite3", getMigrations(), migrate.Up) if err != nil {