-
Notifications
You must be signed in to change notification settings - Fork 257
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
Aborted connection #166
Comments
Hi, usually you need just return connection to the pool (or engine in SQLA case), see example: async def go(loop):
engine = await create_engine(user='root', db='test_pymysql',
host='127.0.0.1', password='', loop=loop)
await create_table(engine)
async with engine.acquire() as conn:
await conn.execute(tbl.insert().values(val='abc'))
await conn.execute(tbl.insert().values(val='xyz'))
async for row in conn.execute(tbl.select()):
print(row.id, row.val)
engine.close()
await engine.wait_closed() pool should care about proper connections closing, during application shutdown |
Hello! I removed the first line of my code (await connection.close()) and i still getting the same error, i checked on my code and is like yours. Any idea on what can be happening? |
This could be result of connection timeout, some of your connections rarely used to execute queries, as result mysql kills it. see more information here: https://www.percona.com/blog/2016/05/16/mysql-got-an-error-reading-communication-packet-errors/ |
you may also need to tweak max_allowed_packet: https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_max_allowed_packet |
I think its not related with mysql settings, let me explain my situation: Im working with microservices architecture, and i've about 10 micro services now, all using mysql, im now developing one with aiomysql (the other where developed under normal PyMySQL and sqlalchemy) and everytime i make a request to my new microservice (the one with aiomysql) i get the aborted connection message at the end of th requests. The connections are created on each request and are dropped at the end (i've middlewares at the start of the request and at the end of th response for this) so my guess is the close signal of the connection is not being sended correctly, i've already tested the max allowed packet and i've duplicated the original value with the same results. Its importat to say this happens with every connection created with aiomysql + sqlalchemy, if my request create 3 connection i get 3 error messages. |
This is happening to me as well. I've wrapped everything into a small class as follows: class DatabaseInterface:
async def connect(self):
db_connection = await aiomysql.connect(host=DB_HOST, port=DB_PORT,
user=DB_USER, password=DB_PASS,
db=DB_NAME, charset='utf8mb4')
return db_connection
async def get_cursor(self):
cnx = await self.connect()
cur = await cnx.cursor(aiomysql.DictCursor)
return cnx, cur
async def select(self, query, args=[]):
cnx, cur = await self.get_cursor()
await cur.execute(query, args)
resultset = await cur.fetchall()
await cur.close()
cnx.close()
return resultset But any time I use, let's say
The database server is Percona Xtradb 5.7 SolvedReplace |
But what about the pool of connections? I use What is the right behavior? |
this commit fixes aio-libs#166
Hello!
Im using aiomysql with SQLAlchemy and i get this warning from mysql:
Aborted connection to db: 'zzzzzzz' user: 'xxxx' host: 'XXXXXXXX' (Got an error reading communication packets)
I've readed a little bit about this error and this seems to happens when you dont close connection properly, im closing my conns like this:
where engine is the var storing the engine and connection the result of engine.acquire(). Maybe im clossing the connection wrong?
Thanks!
The text was updated successfully, but these errors were encountered: