diff options
author | Unknwon <u@gogs.io> | 2019-02-06 18:46:15 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2019-02-06 18:46:15 -0500 |
commit | 0a176df6fb4109793c7efddb493b1f2f4ba1b1b2 (patch) | |
tree | 1c9733dd916fb8decccd0979696c78ffdac5131b /models/models.go | |
parent | d862c43be08dffdf66bebcb5536c04502f190cb6 (diff) |
models: disable idle connection and set connection max life time (#5532)
Diffstat (limited to 'models/models.go')
-rw-r--r-- | models/models.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/models/models.go b/models/models.go index c4b60a0e..4cc6f8c6 100644 --- a/models/models.go +++ b/models/models.go @@ -13,6 +13,7 @@ import ( "os" "path" "strings" + "time" "github.com/Unknwon/com" _ "github.com/denisenkom/go-mssqldb" @@ -200,6 +201,11 @@ func SetEngine() (err error) { return fmt.Errorf("Fail to create 'xorm.log': %v", err) } + // To prevent mystery "MySQL: invalid connection" error, + // see https://github.com/gogs/gogs/issues/5532. + x.SetMaxIdleConns(0) + x.SetConnMaxLifetime(time.Second) + if setting.ProdMode { x.SetLogger(xorm.NewSimpleLogger3(logger, xorm.DEFAULT_LOG_PREFIX, xorm.DEFAULT_LOG_FLAG, core.LOG_WARNING)) } else { |