Skip to content
This repository was archived by the owner on Jan 21, 2022. It is now read-only.

Commit 711645b

Browse files
author
tomponline
committed
fixes reconnect problem when mysql is restarted
1 parent 27dbdf1 commit 711645b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Runrioter Wung <runrioter at gmail.com>
6060
Soroush Pour <me at soroushjp.com>
6161
Stan Putrya <root.vagner at gmail.com>
6262
Stanley Gunawan <gunawan.stanley at gmail.com>
63+
Thomas Parrott <tomp at tomp.uk>
6364
Xiangyu Hu <xiangyu.hu at outlook.com>
6465
Xiaobing Jiang <s7v7nislands at gmail.com>
6566
Xiuming Chen <cc at cxm.cc>

packets.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,15 @@ func (mc *mysqlConn) readPacket() ([]byte, error) {
4646
if data[3] > mc.sequence {
4747
return nil, ErrPktSyncMul
4848
}
49-
return nil, ErrPktSync
49+
50+
// The MariaDB server sends an error packet with sequence numer 0 during
51+
// server shutdown. Continue to process it so the specific error can be
52+
// detected.
53+
if data[3] != 0 {
54+
return nil, ErrPktSync
55+
}
5056
}
57+
5158
mc.sequence++
5259

5360
// packets with length 0 terminate a previous packet which is a
@@ -585,6 +592,13 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) error {
585592
pos = 9
586593
}
587594

595+
// If error code is for ER_CONNECTION_KILLED, then mark connection as bad.
596+
// https://mariadb.com/kb/en/mariadb/mariadb-error-codes/
597+
if errno == 1927 {
598+
errLog.Print("Error ", errno, ": ", string(data[pos:]))
599+
return driver.ErrBadConn
600+
}
601+
588602
// Error Message [string]
589603
return &MySQLError{
590604
Number: errno,

0 commit comments

Comments
 (0)