Skip to content

Commit 3408dca

Browse files
committed
BUG25558885: Set default connection timeout to pure connector/python
With any long running queries, the cext connector/python would lose connection to the server with the message: ERROR 2013 (LOST CONNECTION TO MYSQL SERVER) But the pure connector/python does not throw any such error. To make the behaviour consistent, we set the `connection_timeout` value to None. Test added for regression.
1 parent 0aa4b14 commit 3408dca

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

lib/mysql/connector/abstracts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __init__(self, **kwargs):
6262
self._use_unicode = True
6363
self._get_warnings = False
6464
self._raise_on_warnings = False
65-
self._connection_timeout = None
65+
self._connection_timeout = DEFAULT_CONFIGURATION["connect_timeout"]
6666
self._buffered = False
6767
self._unread_result = False
6868
self._have_next_result = False

lib/mysql/connector/connection.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ def __init__(self, *args, **kwargs):
7878
self._use_unicode = True
7979
self._get_warnings = False
8080
self._raise_on_warnings = False
81-
self._connection_timeout = None
8281
self._buffered = False
8382
self._unread_result = False
8483
self._have_next_result = False

lib/mysql/connector/connection_cext.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def __init__(self, **kwargs):
6565
raise RuntimeError(
6666
"MySQL Connector/Python C Extension not available")
6767
self._cmysql = None
68-
self._connection_timeout = 2
6968
self._columns = []
7069
self.converter = None
7170
super(CMySQLConnection, self).__init__(**kwargs)
@@ -144,7 +143,7 @@ def _open_connection(self):
144143
buffered=self._buffered,
145144
raw=self._raw,
146145
charset_name=charset_name,
147-
connection_timeout=int(self._connection_timeout or 10),
146+
connection_timeout=(self._connection_timeout or 0),
148147
use_unicode=self._use_unicode,
149148
auth_plugin=self._auth_plugin)
150149

tests/test_bugs.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4340,3 +4340,32 @@ def test_pool_exhaustion(self):
43404340
if not self.mysql_server.check_running():
43414341
self.mysql_server.start()
43424342
self.mysql_server.wait_up()
4343+
4344+
4345+
class BugOra25558885(tests.MySQLConnectorTests):
4346+
"""BUG#25558885: ERROR 2013 (LOST CONNECTION TO MYSQL SERVER) USING C
4347+
EXTENSIONS
4348+
"""
4349+
def setUp(self):
4350+
pass
4351+
4352+
def _long_query(self, config, cursor_class):
4353+
db_conn = mysql.connector.connect(**config)
4354+
cur = db_conn.cursor(cursor_class=cursor_class)
4355+
cur.execute("select sleep(15)")
4356+
cur.close()
4357+
db_conn.disconnect()
4358+
4359+
def test_cext_cnx(self):
4360+
config = tests.get_mysql_config()
4361+
config["use_pure"] = False
4362+
del config["connection_timeout"]
4363+
cursor_class = mysql.connector.cursor_cext.CMySQLCursorBufferedRaw
4364+
self._long_query(config, cursor_class)
4365+
4366+
def test_pure_cnx(self):
4367+
config = tests.get_mysql_config()
4368+
config["use_pure"] = True
4369+
del config["connection_timeout"]
4370+
cursor_class = mysql.connector.cursor.MySQLCursorBufferedRaw
4371+
self._long_query(config, cursor_class)

0 commit comments

Comments
 (0)