Skip to content

Commit

Permalink
Fix SSCursor raising query timeout error on wrong query on MySQL DB (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Nothing4You committed Apr 11, 2022
1 parent ef42007 commit 1e474e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -25,6 +25,7 @@ To be included in 1.0.0 (unreleased)
* Add rsa extras_require depending on PyMySQL[rsa] #557
* Migrate to PEP 517 build system #746
* Self-reported `__version__` now returns version generated by `setuptools-scm` during build, otherwise `'unknown'` #748
* Fix SSCursor raising query timeout error on wrong query #428


0.0.22 (2021-11-14)
Expand Down
17 changes: 16 additions & 1 deletion aiomysql/connection.py
Expand Up @@ -1247,7 +1247,22 @@ async def _finish_unbuffered_query(self):
# in fact, no way to stop MySQL from sending all the data after
# executing a query, so we just spin, and wait for an EOF packet.
while self.unbuffered_active:
packet = await self.connection._read_packet()
try:
packet = await self.connection._read_packet()
except OperationalError as e:
# TODO: replace these numbers with constants when available
# TODO: in a new PyMySQL release
if e.args[0] in (
3024, # ER.QUERY_TIMEOUT
1969, # ER.STATEMENT_TIMEOUT
):
# if the query timed out we can simply ignore this error
self.unbuffered_active = False
self.connection = None
return

raise

if self._check_packet_is_eof(packet):
self.unbuffered_active = False
# release reference to kill cyclic reference.
Expand Down

0 comments on commit 1e474e6

Please sign in to comment.