Browse Source

models: disable idle connection and set connection max life time (#5532)

Unknwon 5 years ago
parent
commit
0a176df6fb
3 changed files with 8 additions and 2 deletions
  1. 1 1
      gogs.go
  2. 6 0
      models/models.go
  3. 1 1
      templates/.VERSION

+ 1 - 1
gogs.go

@@ -16,7 +16,7 @@ import (
 	"github.com/gogs/gogs/pkg/setting"
 )
 
-const APP_VER = "0.11.86.0130"
+const APP_VER = "0.11.87.0206"
 
 func init() {
 	setting.AppVer = APP_VER

+ 6 - 0
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 {

+ 1 - 1
templates/.VERSION

@@ -1 +1 @@
-0.11.86.0130
+0.11.87.0206