Skip to content

Connection.close() while another thread runs a query hangs or crashes the interpreter #60

Closed

Description

@zahariash

This work was produced with the help of language models.

Connection.close() destroys the native connection while a query on it is still running in another thread. Depending on the query, an unparameterized query hangs or aborts with heap corruption, a write segfaults, and a parameterized query makes close() wait for it. AsyncConnection.close() hits the same path, since it closes its connections before shutting down its executor.

import threading, time, ladybug as lb

conn = lb.Connection(lb.Database("db"))
q = "WITH range(1, 60000) 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)
conn.close()

Expected: close() returns, and the query ends with an error rather than taking the process down.
Actual: close() hangs, or the interpreter aborts or segfaults.

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: #65

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