Gorm: Getting the following invalid connection issue after few minutes idle time

Created on 30 Dec 2018  路  2Comments  路  Source: go-gorm/gorm

I am getting the following issue after idle time

(invalid connection)
[2018-12-31 01:35:54]
[mysql] 2018/12/31 01:35:54 packets.go:36: unexpected EOF
(invalid connection)
[2018-12-31 01:35:54]

What version of Go are you using (go version)?

go version go1.9 linux/amd64
ENV:
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/shakhawat/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build819959234=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

Which database and its version are you using?

mysql Ver 15.1 Distrib 10.1.35-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

func CheckMobileExist(c *gin.Context) {
mobile := c.Params.ByName("mobile")
type User struct {
Mobile string
}
var user User
//get db connection
var getDB = db.GetDB()
if err := getDB.Where("mobile = ?", mobile).First(&user).Error; err != nil {
fmt.Println(err)
}
c.JSON(200, user)
}

Most helpful comment

Update the mysql-driver, newest version should have a fix for this. See also https://github.blog/2020-05-20-three-bugs-in-the-go-mysql-driver/.

All 2 comments

I get exactly the same problem. Any suggestions?

Update the mysql-driver, newest version should have a fix for this. See also https://github.blog/2020-05-20-three-bugs-in-the-go-mysql-driver/.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bramp picture bramp  路  3Comments

superwf picture superwf  路  3Comments

izouxv picture izouxv  路  3Comments

Quentin-M picture Quentin-M  路  3Comments

sredxny picture sredxny  路  3Comments