Skip to content

set_query_timeout() blocks while a query runs and stalls every Python thread #63

Description

@zahariash

This work was produced with the help of language models.

The engine applies the query timeout (and set_max_threads_for_exec()) under the connection lock that a running query holds for its whole duration. Connection.set_query_timeout() calls the engine right away, so with a query in flight it blocks until that query finishes, and the pybind bindings wait holding the GIL, so every Python thread stalls meanwhile. AsyncConnection.set_query_timeout() with 4 long queries in flight froze the event loop for 12-13 s (0.21.2, CPython 3.13/3.14).

import threading, time, ladybug as lb

conn = lb.Connection(lb.Database(":memory:"))
q = "WITH range(1, 30000) AS r UNWIND r AS x UNWIND r AS y RETURN sum(x * y)"
threading.Thread(target=conn.execute, args=(q,)).start()
time.sleep(0.3)
started = time.monotonic()
conn.set_query_timeout(60_000)
print(time.monotonic() - started)

Expected: set_query_timeout() returns at once, and other threads keep running.
Actual: it returns when the query finishes, seconds later, and no other Python thread runs meanwhile.

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.

A per-call execute(..., timeout_in_ms=...) is proposed separately in (to follow).

Fix: #67

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