Skip to content

A Python UDF that calls back into its own connection hangs forever #61

Closed

Description

@zahariash

This work was produced with the help of language models.

A Python UDF runs inside the query that holds the connection's engine lock, so execute() (or close(), or any other call) on that connection from the UDF waits for itself. The same happens when the UDF is folded while binding (RETURN f(1)), on the calling thread.

import ladybug as lb

conn = lb.Connection(lb.Database(":memory:"))

def reenter(x: int) -> int:
    return conn.execute("RETURN 1").get_next()[0] + x

conn.create_function("reenter", reenter)
conn.execute("UNWIND range(1, 3) AS i RETURN sum(reenter(i))")

Expected: an error saying the connection is busy (after the fix: RuntimeError: A UDF cannot use a connection while it runs a query.).
Actual: never returns.

A UDF that uses another, idle connection works and should keep working.

Reproduced 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