Repository navigation
Conversation
The JS SDK refetches the region settings every max-age while a room is connected. The Rust region cache was only filled on demand, so the first failover after a long call paid for a fetch. The signal task now drives RegionUrlProvider::keep_fresh as one branch of its select loop: no spawned task, and it ends with the session. It refetches when the entry goes stale, at most every default TTL, reads the token before each fetch so a refreshed token is used, and stops on a 401. RegionCache::fresh_for tells it how long to wait. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Devin Review found 1 potential issue.
4 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
| // branch below only drives it. | ||
| let region_refresh = async { | ||
| if inner.options.region_failover { | ||
| RegionUrlProvider::keep_fresh(&inner.project_url, || inner.token.lock().clone()).await; |
There was a problem hiding this comment.
🟡 Wrong cache host after failover
After a room joins a different region host, keep_fresh refreshes only the original project host. Full reconnect instead uses the joined host, so another failed dial waits for region discovery if that host has no fresh entry.
Learn more
The signaling region cache indexes its lists by hostname in fetch_region_urls. On a fallback join, SignalClient::connect passes both the selected region URL and the original project URL to SignalInner::connect. The refresh uses the original project URL, but reconnect_task reads SignalClient::url, which returns the selected region URL. try_restart_connection passes that URL into the replacement session. Its connection attempt starts discovery in parallel, but fallback still awaits discovery if the dial fails before the fetch finishes.
Example: A room joins us.project.livekit.cloud after its initial dial to project.livekit.cloud fails. During the call, refresh keeps project.livekit.cloud warm. A later full reconnect whose first dial to us.project.livekit.cloud fails waits for discovery under us.project.livekit.cloud rather than using the warmed list.
Recommended fix: Carry the project URL separately into full reconnect and use it for region discovery, while retaining the selected region URL for the initial dial and in-place resume. Add a regression test with distinct project and region hostnames and verify that full reconnect reuses the refreshed list.
Was this helpful? React with 👍 or 👎 to provide feedback.
Changeset ✓This PR includes a changeset covering all affected packages:
|
While a room is connected, the JS SDK refetches the region settings each time their
max-ageruns out, with the latest token. The Rust region cache was filled only on demand. The first failover after a long call therefore found an expired list and fetched it first.Change
signal_taskdrivesRegionUrlProvider::keep_freshas one branch of itsselect!loop. There is no spawned task, and the refresh ends with the signal task.keep_freshrefetches the list of the project URL when it goes stale. That is the list a full reconnect reads. It waits at least the default TTL (5 s), which also paces retries after a failed fetch. It reads the session token before each fetch, so a refreshed token is used. It stops on a 401, and does nothing for a URL outside LiveKit Cloud.region_failoveris on.livekit-regionaddsRegionCache::fresh_for, which tellskeep_freshhow long to wait.Unlike JS, the refresh stops when the session closes. JS keeps it for 30 s after a disconnect.
Verified
cargo test -p livekit-signaling -p livekit-region: 65 and 7 tests pass.keep_fresh_refetches_a_stale_list(paused clock): no refetch before 5 s, one refetch after. The cache ages onstd::time::Instant, which a paused clock does not move, so the test starts from a stale entry.keep_fresh_stops_on_a_401: the refresh returns after a 401.the_signal_task_refreshes_the_region_list: the signal task refetches with the session token. It fails when the refresh is removed from the loop.region_cache_reports_how_long_an_entry_stays_freshcoversfresh_for.🤖 Generated with Claude Code