Skip to content

Commit 0929a9e

Browse files
committed
Add 2006 to Mysql expected error codes
1 parent 465afc1 commit 0929a9e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pymysqlreplication/binlogstream.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
from .constants.BINLOG import TABLE_MAP_EVENT, ROTATE_EVENT
1212
from .event import NotImplementedEvent
1313

14+
15+
MYSQL_EXPECTED_ERROR_CODES = [2013, 2006] #2013 Connection Lost
16+
#2006 MySQL server has gone away
17+
1418
class BinLogStreamReader(object):
1519
"""Connect to replication stream and read event
1620
"""
@@ -136,8 +140,7 @@ def fetchone(self):
136140
pkt = self._stream_connection._read_packet()
137141
except pymysql.OperationalError as error:
138142
code, message = error.args
139-
# 2013: Connection Lost
140-
if code == 2013:
143+
if code in MYSQL_EXPECTED_ERROR_CODES:
141144
self.__connected_stream = False
142145
continue
143146

@@ -196,8 +199,7 @@ def __get_table_information(self, schema, table):
196199
return cur.fetchall()
197200
except pymysql.OperationalError as error:
198201
code, message = error.args
199-
# 2013: Connection Lost
200-
if code == 2013:
202+
if code in MYSQL_EXPECTED_ERROR_CODES:
201203
self.__connected_ctl = False
202204
continue
203205
else:

0 commit comments

Comments
 (0)