From edec140c82d1e65cf7ea62b364e99b8f9d248731 Mon Sep 17 00:00:00 2001 From: Jannis Mattheis Date: Sun, 11 Feb 2018 22:37:21 +0100 Subject: [PATCH] Limit sqlite to one connection we use the database connection inside the handlers from the http framework, therefore concurrent access occurs. Sqlite cannot handle concurrent writes, so we limit sqlite to one connection. see https://github.com/mattn/go-sqlite3/issues/274 --- database/database.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/database/database.go b/database/database.go index 5ce8156..7506019 100644 --- a/database/database.go +++ b/database/database.go @@ -15,6 +15,13 @@ func New(dialect, connection, defaultUser, defaultPass string) (*GormDatabase, e if err != nil { return nil, err } + // we use the database connection inside the handlers from the http + // framework, therefore concurrent access occurs. Sqlite cannot handle + // concurrent writes, so we limit sqlite to one connection. + // see https://github.com/mattn/go-sqlite3/issues/274 + if dialect == "sqlite3" { + db.DB().SetMaxOpenConns(1) + } if !db.HasTable(new(model.User)) && !db.HasTable(new(model.Message)) && !db.HasTable(new(model.Client)) && !db.HasTable(new(model.Application)) { db.AutoMigrate(new(model.User), new(model.Application), new(model.Message), new(model.Client))