diff --git a/db/db.go b/db/db.go index e18457f..2ab1b32 100644 --- a/db/db.go +++ b/db/db.go @@ -59,6 +59,12 @@ func Open(path string) (*sql.DB, error) { } } + // SQLite supports concurrent readers but only one writer. With WAL mode, + // reads don't block writes, but multiple Go connections competing for + // the write lock causes SQLITE_BUSY under concurrent load. Limit to one + // connection to serialize all access and eliminate busy errors. + database.SetMaxOpenConns(1) + // Ensure permissions are correct even if the file already existed. if err := os.Chmod(path, 0600); err != nil { _ = database.Close()