Skip to content

Commit 16aaf98

Browse files
committed
BUG20653441: Fix connection hanging when a query is killed
Extra patch to fix the "Unread result found" error caused when a query is killed and cursor.close() is called subsequently.
1 parent 3953b11 commit 16aaf98

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

lib/mysql/connector/connection.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,15 @@ def get_rows(self, count=None, binary=False, columns=None):
437437
if not self.unread_result:
438438
raise errors.InternalError("No result set available.")
439439

440-
if binary:
441-
rows = self._protocol.read_binary_result(
442-
self._socket, columns, count)
443-
else:
444-
rows = self._protocol.read_text_result(self._socket, count)
440+
try:
441+
if binary:
442+
rows = self._protocol.read_binary_result(
443+
self._socket, columns, count)
444+
else:
445+
rows = self._protocol.read_text_result(self._socket, count)
446+
except errors.Error as err:
447+
self.unread_result = False
448+
raise err
445449
if rows[-1] is not None:
446450
self._handle_server_status(rows[-1]['status_flag'])
447451
self.unread_result = False

lib/mysql/connector/connection_cext.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def get_rows(self, count=None, binary=False, columns=None):
269269
break
270270
row = self._cmysql.fetch_row()
271271
except MySQLInterfaceError as exc:
272+
self.free_result()
272273
raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno,
273274
sqlstate=exc.sqlstate)
274275

tests/test_bugs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3645,6 +3645,7 @@ def sleepy_select(cnx):
36453645
cur.fetchall()
36463646
except errors.Error as err:
36473647
cnx.test_error = err
3648+
cur.close()
36483649

36493650
worker = Thread(target=sleepy_select, args=[self.cnx])
36503651
killer = Thread(target=kill, args=[self.cnx.connection_id])

0 commit comments

Comments
 (0)