diff --git a/AUTHORS b/AUTHORS index 3774919d7..da816d5a5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -42,6 +42,7 @@ Runrioter Wung Soroush Pour Stan Putrya Stanley Gunawan +Thomas Parrott Xiaobing Jiang Xiuming Chen diff --git a/packets.go b/packets.go index 8d9166578..ef22c96c3 100644 --- a/packets.go +++ b/packets.go @@ -49,8 +49,15 @@ func (mc *mysqlConn) readPacket() ([]byte, error) { if data[3] > mc.sequence { return nil, ErrPktSyncMul } - return nil, ErrPktSync + + //When MariaDB server is shutdown connection killed packet is sent + //with a zero sequence number. + //Continue to process it so the specific error can be detected. + if data[3] != 0 { + return nil, ErrPktSync + } } + mc.sequence++ // Read packet body [pktLen bytes] @@ -525,6 +532,13 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) error { pos = 9 } + //If error code is for Connection was killed, then return bad connection. + //https://mariadb.com/kb/en/mariadb/mariadb-error-codes/ + if errno == 1927 { + errLog.Print("Error ", errno, ": ", string(data[pos:])) + return driver.ErrBadConn + } + // Error Message [string] return &MySQLError{ Number: errno,