From 327c8380afc6f231a6304fa6bf2a4524cb201716 Mon Sep 17 00:00:00 2001 From: Tigor Hutasuhut Date: Wed, 22 May 2024 08:00:25 +0700 Subject: [PATCH] sqlite: DB connection is not thread safe. Set max open connections to 1 --- db/db.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/db.go b/db/db.go index 9fc4822..93aff1a 100644 --- a/db/db.go +++ b/db/db.go @@ -38,6 +38,9 @@ func Open(cfg *config.Config) (*sql.DB, error) { if err != nil { return db, errs.Wrapw(err, "failed to open database", "driver", driver, "db.string", dsn) } + if driver == "sqlite3" { + db.SetMaxOpenConns(1) // SQLITE is not thread safe. This is to prevent database is locked error. + } if cfg.Bool("db.automigrate") { goose.SetLogger(goose.NopLogger()) goose.SetBaseFS(Migrations)