【问题标题】:Go-sql-driver: Closing bad idle connection: connection reset by peer (mysql)Go-sql-driver:关闭坏空闲连接:对等点重置连接(mysql)
【发布时间】:2022-01-18 00:48:00
【问题描述】:

Go 服务通常会收到错误消息“关闭错误的空闲连接:对等方重置连接”

Error log
[mysql] 2021/01/16 20:08:27 packets.go:122: closing bad idle connection: connection reset by peer
[mysql] 2021/01/16 20:13:27 packets.go:122: closing bad idle connection: connection reset by peer

配置

  • 驱动版本:v1.5.0
  • Go 版本:go1.15.6 darwin/amd64
  • 服务器版本:MySQL 5.7.29

任何想法,如何解决这个问题?

【问题讨论】:

    标签: mysql go


    【解决方案1】:

    如果您的数据库连接长时间保持打开状态,则需要定期检查连接。

    func checkPing() {
       for {
         time.Sleep(time.Second * 15)
         err := DB.DB().Ping()
         if err != nil {
            log.Println(err)
         }
       }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-20
      • 1970-01-01
      • 1970-01-01
      • 2013-07-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多