ziutek / mymysql

MySQL Client API written entirely in Go
Other
735 stars 161 forks source link

panic when running concurrent queries #128

Closed luca-moser closed 8 years ago

luca-moser commented 8 years ago

I am facing a problem with this package with concurrent queries. I am using this driver with the database/sql package with Go 1.6.2. My code correctly closes *db.Stmt and *db.Rows objects after each query.

My pool settings are following:

"connections": {
    "maxOpen": 10,
    "maxIdle": 2,
    "maxLifetime": 60
}

When running multiple queries, the driver simply crashes with the error:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x28 pc=0x557c6c]

goroutine 132 [running]:
panic(0xa15de0, 0xc0820020c0)
        C:/Go/src/runtime/panic.go:481 +0x40d
lucamoser.io/capi/vendor/github.com/ziutek/mymysql/godrv.(*stmt).Close(0xc0821f6ae0, 0x0, 0x0)
        C:/Data/Programming/Projects/goprojects/src/lucamoser.io/capi/vendor/github.com/ziutek/mymysql/godrv/driver.go:191 +0x6c
database/sql.(*driverConn).finalClose(0xc0821fe9a0, 0x0, 0x0)
        C:/Go/src/database/sql/sql.go:356 +0x100
database/sql.(finalCloser).(database/sql.finalClose)-fm(0x0, 0x0)
        C:/Go/src/database/sql/sql.go:449 +0x55
database/sql.(*driverConn).Close(0xc0821fe9a0, 0x0, 0x0)
        C:/Go/src/database/sql/sql.go:349 +0x319
database/sql.(*DB).putConn(0xc0820cce70, 0xc0821fe9a0, 0x0, 0x0)
        C:/Go/src/database/sql/sql.go:909 +0x335
database/sql.(*driverConn).releaseConn(0xc0821fe9a0, 0x0, 0x0)
        C:/Go/src/database/sql/sql.go:284 +0x60
database/sql.(*driverConn).(database/sql.releaseConn)-fm(0x0, 0x0)
        C:/Go/src/database/sql/sql.go:1078 +0x49
database/sql.(*Stmt).Query.func1(0x0, 0x0)
        C:/Go/src/database/sql/sql.go:1622 +0x69
database/sql.(*Rows).Close(0xc082152120, 0x0, 0x0)
        C:/Go/src/database/sql/sql.go:1874 +0x202
database/sql.(*Rows).Next(0xc082152120, 0x18)
        C:/Go/src/database/sql/sql.go:1759 +0x259
lucamoser.io/capi/lib/ctrls.(*DeviceCtrl).GetDeviceComponents(0xc08210a038, 0x8bc, 0x0, 0x0, 0x0, 0x0, 0x0)
        C:/Data/Programming/Projects/goprojects/src/lucamoser.io/capi/lib/ctrls/device.go:502 +0x562
lucamoser.io/capi/lib/ctrls.(*DeviceCtrl).addAdditionalDeviceData.func3(0xc0820027b0, 0xc082038000, 0xc08210a038)
        C:/Data/Programming/Projects/goprojects/src/lucamoser.io/capi/lib/ctrls/device.go:275 +0x224
created by lucamoser.io/capi/lib/ctrls.(*DeviceCtrl).addAdditionalDeviceData
        C:/Data/Programming/Projects/goprojects/src/lucamoser.io/capi/lib/ctrls/device.go:281 +0x13f
exit status 2

I've checked wether any *db.Stmt or *db.Rows objects are nil in my code for whatever reason but they are not. While you provide a separate package for thread-safety, the godrv package uses the native package.

ziutek commented 8 years ago

This reminds me the problem from 2013 (http://grokbase.com/t/gg/golang-nuts/134883hv3h/go-nuts-io-closer-and-closing-previously-closed-object)

I added:

    if s.my == nil {
        panic("godrv: stmt closed twice")
    }

to stmt.Close method.

Try last commit and check panic message.

luca-moser commented 8 years ago

Sorry, I already switched to another driver. My problem was gone anyways after I removed an inner query.