Reputation: 451
A go service usually get the error messages "closing bad idle connection: connection reset by peer"
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
Configuration
Any idea, how to fix this?
Upvotes: 2
Views: 2691
Reputation: 325
If you have a database connection that remains open for a long time, you need to check the connection periodically.
func checkPing() {
for {
time.Sleep(time.Second * 15)
err := DB.DB().Ping()
if err != nil {
log.Println(err)
}
}
}
Upvotes: 1