add connection test cli tool - #1324
Conversation
chenosaurus
commented
Aug 10, 2026
- Add a simple CLI tool to test connection to LK Cloud & report the method
| let stats = match room.get_stats().await { | ||
| Ok(stats) => stats, | ||
| Err(error) => { | ||
| eprintln!("Connected to LiveKit, but could not inspect the connection: {error}"); | ||
| return ExitCode::FAILURE; | ||
| } | ||
| }; |
There was a problem hiding this comment.
🔴 Connection test reports failure because it inspects the connection before it is established
The connection details are requested (room.get_stats() at examples/connection_test/src/main.rs:47) immediately after joining, before the media path has finished being negotiated, so the tool usually prints that no connection could be found and exits with an error.
Impact: Users running the tool typically get "No selected WebRTC candidate pair was found" and a failure exit code instead of the connection report.
Why no selected candidate pair exists yet
Room::connect (livekit/src/room/mod.rs:566) resolves as soon as RtcEngine::connect returns, which only completes the signaling join and spawns session tasks (livekit/src/rtc_engine/rtc_session.rs:695-710). It does not await ICE/DTLS establishment — wait_pc_connection is only used on reconnect paths (livekit/src/rtc_engine/mod.rs:473, livekit/src/rtc_engine/mod.rs:1077).
As a result, at the moment get_stats() runs, neither transport has a selected_candidate_pair_id, so selected_path returns None for both publisher and subscriber and the [] branch (examples/connection_test/src/main.rs:65-68) exits with ExitCode::FAILURE. Additionally, with auto_subscribe = false and no published tracks, connectivity may take even longer or the publisher PC may never negotiate.
A fix would be to wait for RoomEvent::Connected/ConnectionState::Connected from the event receiver (currently discarded as _events) and/or poll get_stats() with a bounded retry/timeout until a selected pair appears.
Prompt for agents
The connection_test CLI calls room.get_stats() immediately after Room::connect returns. Room::connect only completes the signaling join; it does not wait for the peer connections to reach the connected state (wait_pc_connection is only used on reconnect paths in livekit/src/rtc_engine/mod.rs). Consequently the transport stats have no selected_candidate_pair_id yet, selected_path() returns None for both publisher and subscriber, and the tool exits with FAILURE reporting no candidate pair. Consider consuming the RoomEvent receiver (currently bound to `_events`) to wait for the Connected/ConnectionStateChanged event, and/or polling get_stats() on an interval with an overall timeout until a selected candidate pair is present before reporting.
Was this helpful? React with 👍 or 👎 to provide feedback.
| [package] | ||
| name = "connection_test" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| publish = false |
There was a problem hiding this comment.
🟡 Pull request is missing the required changeset file
No changeset entry was added under /.changeset for this change, which the repository's contribution rules require for every pull request.
Impact: Release notes/version bumping tooling has no record of this change.
Rule reference
AGENTS.md ("Documenting changes") states: "Every PR needs a changeset" and "Changeset must list any crates which need to be bumped stemming from the change". Existing entries live in /.changeset (e.g. .changeset/fix-publisher-renegotiation-deadlock.md). This PR adds examples/connection_test but no changeset file.
Was this helpful? React with 👍 or 👎 to provide feedback.
| path = "src/main.rs" | ||
|
|
||
| [dependencies] | ||
| clap = { version = "4.5", features = ["derive"] } |
There was a problem hiding this comment.
issue: livekit, clap, and tokio are workspace deps, set workspace = true rather than hardcoding version or path.