databases
databases copied to clipboard
Program freezes if Connection is lost in the middle of a Transaction
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