Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalidate ResultProxy after releasing a connection #371

Open
zarybnicky opened this issue Jan 15, 2019 · 2 comments
Open

Invalidate ResultProxy after releasing a connection #371

zarybnicky opened this issue Jan 15, 2019 · 2 comments
Labels

Comments

@zarybnicky
Copy link

zarybnicky commented Jan 15, 2019

At work, we spent two days debugging an issue where we had several threads reading from MySQL and we found a non-deterministic bug when after a few hours of running, our service encountered the exception pymysql.err.InternalError: Packet sequence number wrong - got 116 expected 1.

A part of the code reading from MySQL was badly written and looked like this:

async with mysql.acquire() as conn:
    result = conn.execute(text(sql_string))
# [...]
async for row in result:
    pass  # do something with it

After finding the code, it was trivial to fix it (and this was the last place we looked...) so that we don't try to read from the connection after releasing it back into the pool, but it would've been much easier if all ResultProxys were invalidated in such a way that all attempts to read data that's not already cached would result in an exception.

@rberlier
Copy link

rberlier commented Jul 26, 2019

Hi there,
I'm not sure if I should have opened a new issue to report this but the error we're getting on all of our services using aiomysql are pretty mush the same than what @zarybnicky is reporting.

This error occurs for different endpoints => different SQL queries. So here is what is looks like :

File "***************************.py", line 739, 
in ****** await cur.execute(sql_checktable) File "/usr/local/lib/python3.7/site-packages/aiomysql/cursors.py", line 239, 
in execute await self._query(query) File "/usr/local/lib/python3.7/site-packages/aiomysql/cursors.py", line 457, 
in _query await conn.query(q) File "/usr/local/lib/python3.7/site-packages/aiomysql/connection.py", line 428, 
in query await self._read_query_result(unbuffered=unbuffered) File "/usr/local/lib/python3.7/site-packages/aiomysql/connection.py", line 622, 
in _read_query_result await result.read() File "/usr/local/lib/python3.7/site-packages/aiomysql/connection.py", line 1105, 
in read first_packet = await self.connection._read_packet() File "/usr/local/lib/python3.7/site-packages/aiomysql/connection.py", line 576, 
in _read_packet (packet_number, self._next_seq_id)) pymysql.err.InternalError: Packet sequence number wrong - got 97 expected 1

So in a docker container we are running a python web application with this stack that sends queries to a MySQL 5.7 instance ran in Google Cloud SQL:

  • Python 3.7
  • Gunicorn 19.9.0
  • uvloop 0.12.2
  • aiomysql 0.0.20
  • aiohttp 3.5.4
  • aiojobs 0.2.1

Our implementation of aiomysql is exactly this no matter where in the code:

async with connection_pool.acquire() as conn:
    async with conn.cursor() as cur:
        await cur.execute(sql_query, sql_params)
        query_result = await cur.fetchall()

What do you guys think about all this ?

@swordjjjkkk
Copy link

@rberlier i have same problem , have you sloved this ?

@aio-libs aio-libs deleted a comment from aio-libs-bot Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants