Skip to content

Commit

Permalink
Fix intermittent broken pipe issue in log
Browse files Browse the repository at this point in the history
This commit fixes goharbor#4713, by adopting the suggested fix in:
go-sql-driver/mysql#529
When creating the DB instance in orm, call `SetConnMaxLifetime()`
  • Loading branch information
reasonerjt committed Apr 18, 2018
1 parent 2f1989d commit 7fa8261
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/common/dao/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package dao

import (
"fmt"
"time"

"github.com/astaxie/beego/orm"
_ "github.com/go-sql-driver/mysql" //register mysql driver
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7fa8261

Please sign in to comment.