Skip to content

Commit 8eeb3ae

Browse files
amitabnmariz
authored andcommitted
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 9332f01 commit 8eeb3ae

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
@@ -4375,3 +4375,32 @@ def test_pool_exhaustion(self):
43754375
if not self.mysql_server.check_running():
43764376
self.mysql_server.start()
43774377
self.mysql_server.wait_up()
4378+
4379+
4380+
class BugOra25558885(tests.MySQLConnectorTests):
4381+
"""BUG#25558885: ERROR 2013 (LOST CONNECTION TO MYSQL SERVER) USING C
4382+
EXTENSIONS
4383+
"""
4384+
def setUp(self):
4385+
pass
4386+
4387+
def _long_query(self, config, cursor_class):
4388+
db_conn = mysql.connector.connect(**config)
4389+
cur = db_conn.cursor(cursor_class=cursor_class)
4390+
cur.execute("select sleep(15)")
4391+
cur.close()
4392+
db_conn.disconnect()
4393+
4394+
def test_cext_cnx(self):
4395+
config = tests.get_mysql_config()
4396+
config["use_pure"] = False
4397+
del config["connection_timeout"]
4398+
cursor_class = mysql.connector.cursor_cext.CMySQLCursorBufferedRaw
4399+
self._long_query(config, cursor_class)
4400+
4401+
def test_pure_cnx(self):
4402+
config = tests.get_mysql_config()
4403+
config["use_pure"] = True
4404+
del config["connection_timeout"]
4405+
cursor_class = mysql.connector.cursor.MySQLCursorBufferedRaw
4406+
self._long_query(config, cursor_class)

0 commit comments

Comments
 (0)