[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)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM