aiomysql: SSCursor can't close while raise Error
if server send a error to SSCurosr, SSCursor try to call self._result._finish_unbuffered_query in close function
# SSCursor close funcion in cursor.py line 604
if self._result is not None and self._result is conn._result:
await self._result._finish_unbuffered_query()
but there is not a byte to read after recived a error packge, so the loop is allways waiting in the time, the error could’t raise out .
# _finish_unbuffered_query function in connection.py line 1197
while self.unbuffered_active:
packet = await self.connection._read_packet()
I met the bug after I seted a mysql variable
SET GLOBAL MAX_EXECUTION_TIME=3000
a SELECT statement will be aborted if it takes more than 3s.
the connection received a error package with erorno 3024, but the loop is waiting packge to finitshed unbuffered_query
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17 (2 by maintainers)
Commits related to this issue
- fix SSCursor error raise (#428) Fix to raise an error when query execution timeout in server-side cursor - PyMySQL >=0.10.0,<=0.10.1 (to use MysqlPacket->raise_for_error()) — committed to KOR-Believer/aiomysql by KOR-Believer 2 years ago
- Add query timeout tests for #428 — committed to aio-libs/aiomysql by Nothing4You 2 years ago
- Add query timeout tests for #428 (#728) — committed to aio-libs/aiomysql by Nothing4You 2 years ago
- Handle query execution timeout errors when in SSCursor error, partially fixes #428 (#646) Co-authored-by: Richard Schwab <gitrichardschwab-7a2qxq42kj@central-intelligence.agency> — committed to aio-libs/aiomysql by KOR-Believer 2 years ago
- Fix SSCursor raising query timeout error on wrong query on MySQL DB ports https://github.com/PyMySQL/PyMySQL/pull/1035/commits/dd0f854f9307f3ce4040eb63096c6bdbc7f72746 fixes #428 — committed to Nothing4You/aiomysql by Nothing4You 2 years ago
- Fix SSCursor raising query timeout error on wrong query on MySQL DB ports https://github.com/PyMySQL/PyMySQL/pull/1035/commits/dd0f854f9307f3ce4040eb63096c6bdbc7f72746 fixes #428 — committed to Nothing4You/aiomysql by Nothing4You 2 years ago
- Fix SSCursor raising query timeout error on wrong query on MySQL DB (#761) ports https://github.com/PyMySQL/PyMySQL/pull/1035/commits/dd0f854f9307f3ce4040eb63096c6bdbc7f72746 from https://github.com/... — committed to aio-libs/aiomysql by Nothing4You 2 years ago
they actually can, you need to carefully craft the queries though.
example (mysql 8.0):
from mysql 8.0 docs about
SLEEP()
:the key takeaway is that sleep cannot be the only part of the query.
see for example https://github.com/Nothing4You/PyMySQL/blob/8c373feb9036b4c19eb338220f47586f26e5afd0/pymysql/tests/test_cursor.py#L137
https://github.com/PyMySQL/PyMySQL/pull/1035 isn’t ported yet - once I’ve done that I’ll close this.
I fixed the issue for pymysql in the commit