Browse Source

disable idle connection and set connection max life time

Yoginth 6 năm trước cách đây
mục cha
commit
3cb43d6fd2
1 tập tin đã thay đổi với 6 bổ sung0 xóa
  1. 6 0
      models/models.go

+ 6 - 0
models/models.go

@@ -16,6 +16,7 @@ import (
 	"os"
 	"path"
 	"strings"
+	"time"
 
 	// Needed for the MSSSQL driver
 	_ "github.com/denisenkom/go-mssqldb"
@@ -212,6 +213,11 @@ func SetEngine() (err error) {
 	if err != nil {
 		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))