diff --git a/connection.go b/connection.go index a3dc09d2c..bf102cdf9 100644 --- a/connection.go +++ b/connection.go @@ -230,8 +230,10 @@ func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (strin buf, err := mc.buf.takeCompleteBuffer() if err != nil { // can not take the buffer. Something must be wrong with the connection - mc.log(err) - return "", ErrInvalidConn + mc.cleanup() + // interpolateParams would be called before sending any query. + // So its safe to retry. + return "", driver.ErrBadConn } buf = buf[:0] argPos := 0 diff --git a/packets.go b/packets.go index cf3412ff6..033ef201e 100644 --- a/packets.go +++ b/packets.go @@ -117,6 +117,8 @@ func (mc *mysqlConn) writePacket(data []byte) error { // Write packet if mc.writeTimeout > 0 { if err := mc.netConn.SetWriteDeadline(time.Now().Add(mc.writeTimeout)); err != nil { + mc.cleanup() + mc.log(err) return err } }