Repository navigation
[backend:fix] fix same-kernel Python UDF registration and invocation MCDB-103581 - #156
ShubMishra wants to merge 1 commit into
Conversation
66693d2 to
4cb5790
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The unshielded startup cleanup wait allows a second cancellation to invalidate the server’s shared completion Future, causing errors during completion and subsequent shutdown or re-registration.
1 open issue
What changed in this PR
This PR fixes interactive Python UDF registration and allows synchronous SQL calls from the same notebook kernel by moving HTTP serving to a dedicated thread.
Changes:
- Treat error 1347 from
SHOW CREATE FUNCTIONas a missing function while preserving non-replacing registration. - Add threaded interactive serving with startup and shutdown coordination; retain caller-loop serving for published UDFs.
- Expand regression tests for registration, same-kernel invocation, context propagation, and server lifecycle.
| File | Description |
|---|---|
singlestoredb/tests/test_function_url.py |
Adds registration and threaded-server regression tests. |
singlestoredb/functions/ext/function_url.py |
Recognizes WRONG_OBJECT during missing-function checks. |
singlestoredb/apps/_uvicorn_util.py |
Implements threaded serving and loop cleanup. |
singlestoredb/apps/_python_udfs.py |
Selects interactive threaded serving and coordinates its lifecycle. |
Review effort: Balanced
4cb5790 to
759c4dc
Compare
kesmit13
left a comment
There was a problem hiding this comment.
Threaded serving looks solid; one real gap in the 1347 handling, plus two small items.
Also: the shutdown_udf_app docstring still says to call it "on the same event loop as run_udf_app", which no longer applies to the threaded server.
759c4dc to
ef78a7a
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit ef78a7a. Configure here.
ef78a7a to
334fcfe
Compare
334fcfe to
88c4575
Compare
…MCDB-103581 Disambiguate SHOW CREATE error 1347 with catalog checks before stopping a live interactive server. Preserve non-replacing registration and reject procedure, aggregate, table, and view conflicts. Serve interactive UDF callbacks on a dedicated event-loop thread with safe startup, cancellation, and shutdown; retain published serving behavior. Cover registration and lifecycle regressions, including real-engine catalog and error-code checks.
88c4575 to
1ad4347
Compare


Summary
SHOW AGGREGATES. Reject conflicting names before stopping the live server; keep non-replacingCREATEand published/other-session ownership checks.Test Plan
SELECT pulse.double_it_sh_test(2.0);returned 4.0. Cell duration: 529 ms.PYTHONASYNCIODEBUG=1 .venv/bin/python -m pytest -q -n 0 singlestoredb/tests/test_function_url.py singlestoredb/tests/test_udf_event_loop.py- 56 tests and 19 subtests passed on Python 3.11.12 / Uvicorn 0.34.3 against an isolated SingleStore 9.1.1 container. Covers actual 1347/1982/1050 responses, conflicting object types, case variants, schemas, and lifecycle behavior.git diff --checkpassed. Full engine-protocol suites were not run locally.The pure-Python fallback warning is expected with
SINGLESTOREDB_BUILD_EXTENSION=0; it did not prevent registration or invocation.Runtime Impact
Interactive apps gain one persistent HTTP serving thread/event loop, not a new server thread per query. Startup/shutdown coordination is outside the request path; existing UDF dispatch remains unchanged. The new loop can own an executor for synchronous UDF work. Latency, throughput, and memory overhead have not been benchmarked; the screenshot is a functional smoke test.
Deployment Plan
JIRA Issues
Resolves MCDB-103581.
Note
Medium Risk
Changes interactive UDF server threading and registration preflight against the database catalog; incorrect conflict detection or shutdown could break notebook UDF registration or leave listeners open, though published UDF paths are unchanged.
Overview
Fixes same-kernel interactive Python UDF registration and invocation by serving HTTP on a dedicated thread (
ThreadedUvicornServer) instead of the notebook asyncio loop, so synchronous SQL-in-notebook calls no longer deadlock the cell. Startup/shutdown now support both async tasks and threadFutures, including cleanup when startup fails or is cancelled, and updated docs that interactive shutdown may run from a different loop in the same kernel.Interactive preflight now treats
SHOW CREATE FUNCTIONwrong-object (1347) as a possible name clash: it checks information_schema andSHOW AGGREGATES, raises a clear RuntimeError when the name is taken by a procedure/table/view/aggregate, and does not tear down the live UDF server when preflight fails. Free names still register with non-replacingCREATE.Published UDF serving on the notebook loop is unchanged. Tests cover threaded lifecycle, context propagation, catalog conflicts, and integration against a real engine.
Reviewed by Cursor Bugbot for commit 1ad4347. Bugbot is set up for automated code reviews on this repo. Configure here.