aiomysql icon indicating copy to clipboard operation
aiomysql copied to clipboard

Pool does not reset connections after they're returned to the pool

Open cole-dda opened this issue 5 years ago • 3 comments

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

cole-dda avatar Feb 04 '20 15:02 cole-dda

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?

MateuszCzubak avatar May 29 '20 10:05 MateuszCzubak

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

Nothing4You avatar Jul 10 '22 22:07 Nothing4You

see also

  • #562

Nothing4You avatar Jul 11 '22 00:07 Nothing4You