aiomysql
aiomysql copied to clipboard
Pool does not reset connections after they're returned to the pool
async with aiomysql.create_pool(autocommit=False) as pool:
async with pool.connect() as conn:
conn.autocommit(True)
When next resue connection,the connection maybe autocommit=True,but pool settings is autocommit=False。
fix:
def release(conn):
conn.autocommit= init_autocommit
I'm not really sure if this is a bug. If you manipulate with the connection state, shouldn't it be your responsibility to change the state back the original one?
As mentioned in #679, this could be dealt with by resetting the connection when it's returned to the pool.
MySQL supports this since version 5.7.3, which means all currently supported versions include this.
https://dev.mysql.com/doc/internals/en/com-reset-connection.html
MariaDB supports this since 10.2.4: https://mariadb.com/kb/en/com_reset_connection/, which means all currently supported versions include this.
Note that at least MariaDB explicitly notes that the Database will NOT be reset to initial value
.
MySQL does not explicitly mention resetting the DB, so it probably doesn't reset it either: https://dev.mysql.com/doc/c-api/8.0/en/mysql-reset-connection.html
It looks like aiopg
currently deals with this by checking transaction state and closing connections when they're returned with active transactions: https://github.com/aio-libs/aiopg/blob/7f40980694085bb176d9ef2a5529f026941183db/aiopg/pool.py#L390-L398
see also
- #562