From d35ca9d98ffe6859912fcafb3f461fcae33fc29b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 12 May 2022 13:58:15 +0200 Subject: [PATCH] Manager: limit database connections Limit the database connection pool to only a single connection. I hope that this will solve the intermittent `SQLITE_BUSY` errors I've been seeing. --- internal/manager/persistence/db.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/internal/manager/persistence/db.go b/internal/manager/persistence/db.go index db415602..ac61e91f 100644 --- a/internal/manager/persistence/db.go +++ b/internal/manager/persistence/db.go @@ -62,6 +62,16 @@ func openDBWithConfig(dsn string, config *gorm.Config) (*DB, error) { return nil, err } + // Use the generic sql.DB interface to set some connection pool options. + sqlDB, err := gormDB.DB() + if err != nil { + return nil, err + } + // Only allow a single database connection, to avoid SQLITE_BUSY errors. + // It's not certain that this'll improve the situation, but it's worth a try. + sqlDB.SetMaxIdleConns(1) // Max num of connections in the idle connection pool. + sqlDB.SetMaxOpenConns(1) // Max num of open connections to the database. + db := DB{ gormDB: gormDB, }