Repository navigation
Conversation
SignalClient::connect fetched the region list only after the first attempt failed, which added up to the 3 s fetch timeout to every failover. The fetch now runs next to the first attempt in one select loop, with no spawned task, and is dropped when the attempt succeeds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Devin Review found 2 potential issues.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| else { | ||
| return Err(SignalError::Cancelled); | ||
| let urls = match fetched { | ||
| Some(urls) => urls, |
There was a problem hiding this comment.
🟡 Redundant region request delays failover
When a region response arrives after the first dial fails with max-age=0, connect requests it again before trying a fallback. The same recheck repeats a failed refresh when fetch_region_urls returns expired cached regions. The extra request can add three seconds before failover.
Learn more
fetch_region_urls returns both newly fetched URLs and stale fallback URLs as Ok. When the first dial fails before the region request completes, connect already waits for that request under the cancellation token. Looking up the list again immediately sends another request if the server set a zero cache lifetime or if a failed refresh left the stale entry unchanged. The region HTTP timeout applies separately to each request.
Example: The cloud WebSocket fails before region discovery finishes. Discovery then returns a usable backup region with Cache-Control: max-age=0. Instead of dialing that backup, the SDK waits for a second discovery request, which can time out before the SDK uses the list it already received.
Recommended fix: Use the result directly when failover had to await the original request. For results completed during the dial, distinguish a previously fresh list from a stale fallback returned after a refresh failure, and revalidate only the previously fresh list. Preserve the cancellation check before using either result.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Fixed in 0814854: at the failover, the list is read again through the cache, which refetches it only when it went stale. Test: failover_refreshes_a_list_that_expired_during_the_attempt.
The list fetched next to the first attempt can expire before that attempt fails: the default max-age and the join timeout are both 5 s. The failover now reads the list again through the cache, which refetches only a stale list and returns a fresh one at once. That read also goes through run_until_cancelled again. Without it, a cancel that landed while the failed attempt closed its transport returned the join error instead of Cancelled when there was no region to try. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Changeset ✓This PR includes a changeset covering all affected packages:
|
SignalClient::connectfetched the region list of a LiveKit Cloud project only after the first attempt failed. Every region failover therefore waited for that fetch, up to the 3 s fetch timeout, after the failed attempt. The JS SDK starts the fetch when the connect starts.Change
select!loop insideconnect, with no spawned task. When the attempt succeeds, the fetch is dropped. Withregion_failoveroff, there is no fetch.connectlets a fetch that is still running finish. It then reads the list again through the cache. A fresh list comes back at once, and a list that expired during the attempt is fetched again: the default max-age and the join timeout are both 5 s.Cancelled.A connect to a project with a fresh cached list makes no request. Otherwise each connect now makes one region request, also when the first attempt succeeds.
Verified
cargo test -p livekit-signaling: 59 tests pass.connect_fetches_regions_during_the_first_attempt: the region request goes out while the first attempt still waits on a server that never answers. Without the change it times out.failover_refreshes_a_list_that_expired_during_the_attempt: the mock serves the list withmax-age=0, and the failover fetches it a second time. Without the revalidation, there is one fetch.cancel_during_the_attempt_cleanup_returns_cancelled(paused clock): the failed attempt's transport never finishes closing, and the test cancels during that close. Without the change, the join error comes back.cancel_interrupts_an_attempt_waiting_on_the_serverasserted that a cancelled connect made no region request. That is no longer true, so it now relies on theCancellederror: a region retry would return the mock region's error instead.🤖 Generated with Claude Code