databases icon indicating copy to clipboard operation
databases copied to clipboard

Program freezes if Connection is lost in the middle of a Transaction

Open ondrejbenes opened this issue 3 years ago • 0 comments

Current behavior When connection to the database is dropped (e.g. due to Kubernetes Pod restart), the program freezes. This only seems to manifest when wrapped in a transaction.

Expected behavior An exception is raised.

Reproducer

import asyncio
import logging

import databases

logger = logging.getLogger(__name__)


URL = "<...>"


async def main():

    db = databases.Database(URL)

    async with db:
        async with db.connection() as conn:

            async with conn.transaction():
                logger.warning("Sleeping...")

                # Restart MariaDB container

                await asyncio.sleep(10)

                logger.warning("Woke up...")

                # Program gets stuck on the line belowe
                val = await conn.execute("SELECT 1")

                # This will not get printed
                logger.warning("OK")


asyncio.run(main())

Versions databases==0.5.5 SQLAlchemy==1.4.31

ondrejbenes avatar Feb 19 '22 13:02 ondrejbenes