1. 程式人生 > 其它 >[Go] 解決packets.go:36: read tcp 127.0.0.1:51139->127.0.0.1:3306: wsarecv: An established connection was aborted by the software in your host ma chine.

[Go] 解決packets.go:36: read tcp 127.0.0.1:51139->127.0.0.1:3306: wsarecv: An established connection was aborted by the software in your host ma chine.

這是因為資料庫的超時時間比較短,連線被mysql服務關閉了

程式還在使用舊連線查詢資料庫

比如gorm

我們程式裡設定下時間舊可以了,時間比超時時間短一些

DB.DB().SetConnMaxLifetime(59 * time.Second)

    DB, err = gorm.Open("mysql", dsn)
    if err != nil {
        log.Println(err)

        panic("資料庫連線失敗!")
        return err
    }
    DB.SingularTable(true)
    DB.LogMode(
true) DB.DB().SetMaxIdleConns(10) DB.DB().SetMaxOpenConns(100) DB.DB().SetConnMaxLifetime(59 * time.Second)

開源作品

GO-FLY,一套可私有化部署的免費開源客服系統,安裝過程不超過五分鐘(超過你打我 !),基於Golang開發,二進位制檔案可直接使用無需搭開發環境,下載zip解壓即可,僅依賴MySQL資料庫,是一個開箱即用的網頁線上客服系統,致力於幫助廣大開發者/中小站長快速整合私有客服功能 github地址:go-fly 官網地址:https://gofly.sopans.com

讚賞作者

微信交流