From 7fa82616612f60b3122778eaecdcb1b35f802477 Mon Sep 17 00:00:00 2001 From: Tan Jiang Date: Wed, 18 Apr 2018 17:39:13 +0800 Subject: [PATCH] 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()` --- src/common/dao/mysql.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common/dao/mysql.go b/src/common/dao/mysql.go index 8313add26..1999b0208 100644 --- a/src/common/dao/mysql.go +++ b/src/common/dao/mysql.go @@ -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