Skip to content

fix(core): allow RPC handler registration after connect#61

Merged
pham-tuan-binh merged 2 commits into
mainfrom
fix/rpc-register-post-connect
Jul 8, 2026
Merged

fix(core): allow RPC handler registration after connect#61
pham-tuan-binh merged 2 commits into
mainfrom
fix/rpc-register-post-connect

Conversation

@pham-tuan-binh

Copy link
Copy Markdown
Collaborator

Fixes #59.

Problem

Registering a foreign async RPC handler after connect() panicked:

InternalError: there is no reactor running, must be called from the context of a Tokio 1.x runtime

The SDK's register_rpc_method calls publisher_negotiation_needed(), which tokio::spawns. When Portal::register_rpc_method runs on a live participant from a foreign thread (a binding's asyncio loop, no runtime context), that spawn panics.

Fix

Capture the tokio runtime handle that connect() runs on, and enter it around the live register_handler_on call so the internal spawn lands on that runtime. Pre-connect registration was already fine (handlers are applied inside connect(), which runs on the runtime).

Tests

New tests/integration/test_rpc.py:

  • test_rpc_register_after_connect — the regression guard (previously panicked)
  • test_rpc_register_before_connect — pre-connect path still works
  • test_rpc_handler_error_propagates — application errors surface on the caller

Verification

  • cargo clippy --workspace -- -D warnings clean
  • cargo fmt --check clean
  • cargo test --workspace --locked — 96 passed
  • Unit pytest — 47 passed
  • New RPC integration tests against a local LiveKit server — 3 passed

Independent of #58 (role-split bindings); branched from main.

Registering an RPC handler on a live LocalParticipant triggers SDK
publisher negotiation, which `tokio::spawn`s internally. When
`register_rpc_method` is called from a foreign thread with no runtime
context (a binding's asyncio loop), that spawn panicked with "there is
no reactor running, must be called from the context of a Tokio 1.x
runtime".

Capture the runtime handle `connect()` runs on and enter it around the
live-registration call so the spawn lands on that runtime. Pre-connect
registration was unaffected (handlers are applied inside connect, which
already runs on the runtime).

Fixes #59
Adds integration coverage for the post-connect registration regression
(previously panicked), the pre-connect path, and handler error
propagation.
@pham-tuan-binh pham-tuan-binh merged commit bfd0186 into main Jul 8, 2026
7 checks passed
@pham-tuan-binh pham-tuan-binh deleted the fix/rpc-register-post-connect branch July 8, 2026 01:01
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.

Foreign async RPC handler registration after connect panics (no reactor running)

2 participants