asyncmy
asyncmy copied to clipboard
Aborted connections
I am getting the following error:
2022-07-10T08:18:46.290142Z 10 [Note] Aborted connection 10 to db: '...' user: '...' host: '...' (Got an error reading communication packets)
This happens on a simple use case:
import asyncio
import asyncmy
async def main():
conn = await asyncmy.connect(...)
async with conn.cursor() as cursor:
await cursor.execute("SELECT 1")
ret = await cursor.fetchall()
print(ret)
asyncio.run(main())
Am I doing something wrong with connection management?
@ahopkins were you able to resolve this? I've been encountering this, and I'm also wondering if I'm doing something incorrect with connection management.
nope
@long2ice any insight here?
No idea also
In case it helps, I was able to track down the source of this for me.
I was using a simple function similar to the one above to validate a database is available.
What I found was that MySQL (at least the current mysql:latest image) starts a temporary server during the init process of the database. Once complete, the server is stopped and restarted for a final time.
I was receiving this error when connecting during this short timeframe that the temporary server is started and stopped. I resolved this by sleeping longer and catching the OperationalError exception for this specific case.
Here are the docker logs from the mysql:latest container:
repository-mysql-1 | 2023-04-18 15:24:16+00:00 [Note] [Entrypoint]: Creating database db
repository-mysql-1 | 2023-04-18 15:24:16+00:00 [Note] [Entrypoint]: Creating user app
repository-mysql-1 | 2023-04-18 15:24:16+00:00 [Note] [Entrypoint]: Giving user app access to schema db
repository-mysql-1 |
repository-mysql-1 | 2023-04-18 15:24:16+00:00 [Note] [Entrypoint]: Stopping temporary server
repository-mysql-1 | 2023-04-18T15:24:16.277180Z 13 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.32).
repository-mysql-1 | 2023-04-18T15:24:18.238350Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.32) MySQL Community Server - GPL.
repository-mysql-1 | 2023-04-18 15:24:18+00:00 [Note] [Entrypoint]: Temporary server stopped
repository-mysql-1 |
repository-mysql-1 | 2023-04-18 15:24:18+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
repository-mysql-1 |