Fix intermittent broken pipe issue in log

This commit fixes #4713, by adopting the suggested fix in:
https://github.com/go-sql-driver/mysql/issues/529
When creating the DB instance in orm, call `SetConnMaxLifetime()`
This commit is contained in:
Tan Jiang 2018-04-18 17:39:13 +08:00
parent 2f1989d211
commit 7fa8261661

View File

@ -16,6 +16,7 @@ package dao
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
_ "github.com/go-sql-driver/mysql" //register mysql driver
@ -58,7 +59,12 @@ func (m *mysql) Register(alias ...string) error {
}
conn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", m.usr,
m.pwd, m.host, m.port, m.database)
return orm.RegisterDataBase(an, "mysql", conn)
if err := orm.RegisterDataBase(an, "mysql", conn); err != nil {
return err
}
db, _ := orm.GetDB(an)
db.SetConnMaxLifetime(5 * time.Minute)
return nil
}
// Name returns the name of MySQL