fix(sqlite): Limit concurrent writes to avoid SQLITE_BUSY errors
Some checks failed
Release v2.X / Prep (push) Has been cancelled
Release v2.X / Installer linux (push) Has been cancelled
Release v2.X / Installer windows (push) Has been cancelled

https://github.com/safing/portmaster/issues/1848
This commit is contained in:
Alexandr Stelnykovych 2025-05-30 13:14:55 +03:00
parent 8a0879e2e6
commit e5715a9550

View file

@ -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 {