diff --git a/connection.go b/connection.go index 2bc081c43..768794f8e 100644 --- a/connection.go +++ b/connection.go @@ -137,7 +137,7 @@ func (mc *mysqlConn) Close() (err error) { } mc.cleanup() - + mc.clearResult() return } @@ -152,13 +152,16 @@ func (mc *mysqlConn) cleanup() { // Makes cleanup idempotent close(mc.closech) - if mc.netConn == nil { + nc := mc.netConn + if nc == nil { return } - if err := mc.netConn.Close(); err != nil { + if err := nc.Close(); err != nil { mc.log(err) } - mc.clearResult() + // This function can be called from multiple goroutines. + // So we can not mc.clearResult() here. + // Caller should do it if they are in safe goroutine. } func (mc *mysqlConn) error() error {