Skip to content

AsyncConnection: a cancelled execute() returns None instead of raising #59

Closed

Description

@zahariash

This work was produced with the help of language models.

AsyncConnection.execute() catches asyncio.CancelledError, interrupts the connection and returns None. A cancelled task therefore looks like a normal return: task.cancelled() is false, loops keep running after cancellation, and asyncio.wait_for() / asyncio.timeout() return None instead of raising TimeoutError.

In the same code path:

  • Cancelling a task that is still waiting for a free connection interrupts whatever query runs on that connection, i.e. another task's query.
  • The connection counter is released when the awaiting task exits, while the query may still be running.
  • execute() with a PreparedStatement from a connection outside the pool raises UnboundLocalError.
import asyncio, ladybug as lb

async def main():
    ac = lb.AsyncConnection(lb.Database(":memory:"))
    q = "WITH range(1, 30000) AS r UNWIND r AS x UNWIND r AS y RETURN sum(x * y)"
    print(await asyncio.wait_for(ac.execute(q), 0.5))

asyncio.run(main())

Expected: asyncio.TimeoutError after 0.5 s.
Actual: prints None.

Reproduced with the ladybug==0.21.2 wheel on CPython 3.13.16 and 3.14.8, and on main (548c183) with CPython 3.12.

Fix: #64

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions