aiomysql icon indicating copy to clipboard operation
aiomysql copied to clipboard

OperationalError during ROLLBACK or COMMIT deadlocks entire sa engine

Open Harut opened this issue 6 years ago • 0 comments

Didn't dive deeper, because in my case it is enough to just set autocommit=True and get rid of all transactions, but here is a minimal test reproducing a problem (v0.0.19), at least giving very similar results:

engine = await create_engine(
    ...
    autocommit=False,
)

async def test_mysql_connection_error():
    used = engine._pool._used
    assert len(used) == 0

    with pytest.raises(aiomysql.OperationalError):
        with mock.patch('aiomysql.sa.connection.SAConnection.execute',
                        side_effect=aiomysql.OperationalError):
            with mock.patch('aiomysql.sa.transaction.Transaction.rollback',
                            side_effect=aiomysql.OperationalError):
                async with engine.acquire() as conn:  # type: SAConnection
                    async with conn.begin():
                        qs = table.select()
                        await conn.execute(qs)

    used = mysql.engine._pool._used
    assert len(used) == 0


async def test_mysql_connection_error2():
    used = mysql.engine._pool._used
    assert len(used) == 0

    with pytest.raises(aiomysql.OperationalError):
            with mock.patch('aiomysql.sa.transaction.Transaction.commit',
                            side_effect=aiomysql.OperationalError):
                async with engine.acquire() as conn:  # type: SAConnection
                    async with conn.begin():
                        qs = table.select()
                        await conn.execute(qs)

    used = mysql.engine._pool._used
    assert len(used) == 0

Harut avatar Nov 06 '18 20:11 Harut