From 74c0b49ecc8f80fe7cd6607eff4120b51f465de7 Mon Sep 17 00:00:00 2001 From: tomponline Date: Fri, 29 Apr 2016 12:29:31 +0000 Subject: [PATCH 1/8] fixes reconnect problem when mysql is restarted --- packets.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packets.go b/packets.go index 8d9166578..0556cced2 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 } + + if data[3] == 0 { + mc.Close() + return nil, driver.ErrBadConn + } + return nil, ErrPktSync } + mc.sequence++ // Read packet body [pktLen bytes] From 4d31bd275b9787f687e53684f359909766ff5751 Mon Sep 17 00:00:00 2001 From: tomponline Date: Fri, 29 Apr 2016 12:32:41 +0000 Subject: [PATCH 2/8] contributors update --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 3774919d7..20a789373 100644 --- a/AUTHORS +++ b/AUTHORS @@ -44,6 +44,7 @@ Stan Putrya Stanley Gunawan Xiaobing Jiang Xiuming Chen +Thomas Parrott # Organizations From 2b2d33c0d7160b39b88fa83c215d3665b2f24024 Mon Sep 17 00:00:00 2001 From: tomponline Date: Fri, 29 Apr 2016 12:45:00 +0000 Subject: [PATCH 3/8] gob --- packets.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packets.go b/packets.go index 0556cced2..f202b275c 100644 --- a/packets.go +++ b/packets.go @@ -50,6 +50,8 @@ func (mc *mysqlConn) readPacket() ([]byte, error) { return nil, ErrPktSyncMul } + //When MySQL server is shutdown a packet with a zero sequence seems + //to be sent to the old connection which is read on next query. if data[3] == 0 { mc.Close() return nil, driver.ErrBadConn From 78a3d69ecc3e8c2355483d6286b7851a4940146b Mon Sep 17 00:00:00 2001 From: tomponline Date: Fri, 29 Apr 2016 13:39:46 +0000 Subject: [PATCH 4/8] improves patch to account for MariaDB 10 error code 1927 --- packets.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packets.go b/packets.go index f202b275c..4f7f57956 100644 --- a/packets.go +++ b/packets.go @@ -50,14 +50,12 @@ func (mc *mysqlConn) readPacket() ([]byte, error) { return nil, ErrPktSyncMul } - //When MySQL server is shutdown a packet with a zero sequence seems - //to be sent to the old connection which is read on next query. - if data[3] == 0 { - mc.Close() - return nil, driver.ErrBadConn + //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 } - - return nil, ErrPktSync } mc.sequence++ @@ -534,6 +532,12 @@ 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 { + return driver.ErrBadConn + } + // Error Message [string] return &MySQLError{ Number: errno, From 80b57cc22f3bc732b84cd0185825b4dfcebeada0 Mon Sep 17 00:00:00 2001 From: tomponline Date: Fri, 29 Apr 2016 13:40:35 +0000 Subject: [PATCH 5/8] only detect zero sequence number --- packets.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packets.go b/packets.go index 4f7f57956..2680b507d 100644 --- a/packets.go +++ b/packets.go @@ -53,7 +53,7 @@ func (mc *mysqlConn) readPacket() ([]byte, error) { //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 { + if data[3] != 0 { return nil, ErrPktSync } } From 7c6122e4e947fbbf7fad93961f457560ccbb7f66 Mon Sep 17 00:00:00 2001 From: tomponline Date: Fri, 29 Apr 2016 13:43:08 +0000 Subject: [PATCH 6/8] better logging --- packets.go | 1 + 1 file changed, 1 insertion(+) diff --git a/packets.go b/packets.go index 2680b507d..a2e438226 100644 --- a/packets.go +++ b/packets.go @@ -535,6 +535,7 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) error { //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(string(data[pos:])) return driver.ErrBadConn } From ac5e404322e31e7709afccec40a5719eb4089462 Mon Sep 17 00:00:00 2001 From: tomponline Date: Mon, 9 May 2016 21:30:13 +0000 Subject: [PATCH 7/8] logging of conn killed error code --- packets.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packets.go b/packets.go index a2e438226..ef22c96c3 100644 --- a/packets.go +++ b/packets.go @@ -535,7 +535,7 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) error { //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(string(data[pos:])) + errLog.Print("Error ", errno, ": ", string(data[pos:])) return driver.ErrBadConn } From 53a7eb2194ee301e7c2ca6872505a0ef7848bd5a Mon Sep 17 00:00:00 2001 From: tomponline Date: Mon, 9 May 2016 21:31:54 +0000 Subject: [PATCH 8/8] ordered authors --- AUTHORS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 20a789373..da816d5a5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -42,9 +42,9 @@ Runrioter Wung Soroush Pour Stan Putrya Stanley Gunawan +Thomas Parrott Xiaobing Jiang Xiuming Chen -Thomas Parrott # Organizations