Skip to content

fix(connection): keep the UDF close() error when the UDF runs on the query thread - #71

Merged
adsharma merged 2 commits into
LadybugDB:mainfrom
zahariash:fix/close-from-inline-udf
Oct 22, 2026
Merged

adsharma merged 2 commits into
LadybugDB:mainfrom
zahariash:fix/close-from-inline-udf

Conversation

@zahariash

@zahariash zahariash commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

This work was produced with the help of language models.

close() called from a UDF while its connection runs a query should raise "close() cannot be called from a UDF while the connection runs a query." It raises "close() cannot be called from a call on the same connection." instead whenever the UDF runs on the thread that issued the query: that thread's stack then holds the connection's own call below the UDF marker, and close() checks for the call first. On main this already happens when a constant argument is folded while binding (RETURN closer(1)). With LadybugDB/ladybug#1297, which runs a one-thread task on the calling thread, it also happens for a UDF over rows, and test_close_with_query_in_flight[close_from_a_udf] fails. A UDF on an engine worker thread is unaffected. The close is refused either way; only the message is wrong.

Fix. The same-thread check uses the UDF message when a UDF was entered after the connection's call (_called_from_udf), as the worker-thread path already does.

Tests. A new close_from_a_folded_udf scenario runs RETURN closer(1) with a UDF that closes its connection; it fails on main without the fix. The C-API backend cannot register UDFs yet, so the scenario is listed in capi_xfails.py next to close_from_a_udf. With the fix, test_connection_close.py passes on pybind against ladybug main and against LadybugDB/ladybug#1297, and the rest of the suite (without the torch-geometric and JSON-extension tests) gives the same results against LadybugDB/ladybug#1297 as against main.

…query thread

close() called from a UDF while its connection runs a query raised "close() cannot be called
from a call on the same connection" instead of the UDF message whenever the UDF ran on the
thread that issued the query: that thread's stack holds the connection's own call below the UDF
marker. A constant argument folded while binding already runs the UDF there, and an engine that
runs a one-thread task on the calling thread does so for every such task. The same-thread check
now uses the UDF message when a UDF was entered after the connection's call, as the worker path
does. The new close_from_a_folded_udf scenario covers it with RETURN closer(1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@adsharma adsharma left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI still failing against a fresh main repo build

…lure

The C-API backend cannot register UDFs yet, so close_from_a_folded_udf stops at
create_function() with NotImplementedError, like close_from_a_udf already listed
here. The C-API job never reached pytest on this branch before, because its JSON
extension smoke step crashed on the ladybug main build of the time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zahariash

Copy link
Copy Markdown
Contributor Author

The failure was in my new test. close_from_a_folded_udf registers a UDF, which the C-API backend can't do yet. When I opened the PR, this job crashed in the JSON smoke step before it reached pytest, so I didn't see it. b56db24 lists the scenario in capi_xfails.py next to close_from_a_udf.

Running the C-API job locally against 319bb92, I also hit a flaky failure that main has too. test_timeout.py errors with Mmap for size 8796093022208 failed. in most runs. That fixture came from #67, and #73 fixes it. If the rerun here shows that error, it's this flake.

@adsharma
adsharma merged commit 49837b1 into LadybugDB:main Oct 22, 2026
2 checks passed
@zahariash
zahariash deleted the fix/close-from-inline-udf branch October 22, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants