Manager: increase 'database open' timeout to 1 minute

Increase the 'database open' timeout from 5 seconds to 1 minute. This
timeout also covers database migrations, and the recently added one that
adds a bunch of `NOT NULL` clauses could time out with the old 5 sec
limit.

The reason this takes long, is that SQLite doesn't directly support
adding `NOT NULL` clauses to columns. The only way to do this is to
create a new table with the desired schema, copy all data over, then
drop the old table. And with a big enough database, this takes time.
This commit is contained in:
Sybren A. Stüvel 2024-03-06 11:50:14 +01:00
parent 16114ee529
commit 7277286391

@ -56,6 +56,10 @@ const (
developmentWebInterfacePort = 8081 developmentWebInterfacePort = 8081
webappEntryPoint = "index.html" webappEntryPoint = "index.html"
// dbOpenTimeout is the time the persistence layer gets to open the database.
// This includes database migrations, which can take some time to perform.
dbOpenTimeout = 1 * time.Minute
) )
type shutdownFunc func() type shutdownFunc func()
@ -379,7 +383,7 @@ func openDB(configService config.Service) *persistence.DB {
log.Fatal().Msg("configure the database in flamenco-manager.yaml") log.Fatal().Msg("configure the database in flamenco-manager.yaml")
} }
dbCtx, dbCtxCancel := context.WithTimeout(context.Background(), 5*time.Second) dbCtx, dbCtxCancel := context.WithTimeout(context.Background(), dbOpenTimeout)
defer dbCtxCancel() defer dbCtxCancel()
persist, err := persistence.OpenDB(dbCtx, dsn) persist, err := persistence.OpenDB(dbCtx, dsn)
if err != nil { if err != nil {