Skip to content

Fall back to the expired region cache when the refresh fails - #2291

Open
lukasIO wants to merge 1 commit into
mainfrom
claude/regionurlprovider-cache-fallback-9d74b2
Open

lukasIO wants to merge 1 commit into
mainfrom
claude/regionurlprovider-cache-fallback-9d74b2

Conversation

@lukasIO

@lukasIO lukasIO commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

What and why

On LiveKit Cloud, the SDK picks a region from a cached region list. The region settings endpoint sends a max-age, and the cached list expires at that age. Today, if the list is expired and the endpoint is unreachable, getNextBestRegionUrl throws, and the connection or the full reconnect fails. An expired list still names regions that most likely work, so the SDK can try them instead of failing.

Change

If the refresh fails, getNextBestRegionUrl uses the expired list and logs a warning. The failed refresh does not change the cache entry. The background refetch keeps retrying on its own schedule.

Three cases still throw:

  • The fetch was aborted (Cancelled). An aborted reconnect must stop.
  • The endpoint rejected the token with a 401 (NotAllowed). The signal connection rejects the same token, and the background refetch already treats this error as final.
  • No list is cached yet.

Verified

  • npx vitest run src/room/RegionUrlProvider.test.ts: 53 tests pass. The test falls back to the expired cache when the refresh fails expires the cache and then makes the refresh fail, first with a 500 and then with a network error. Both calls return the cached region. The test does not fall back to the expired cache when the token is rejected makes the refresh return a 401 and expects a NotAllowed error.
  • The old test preserves cache when one instance fails to fetch expected that a 500 from the refresh throws. The new fallback test replaces it.
  • npx tsc --noEmit passes.

Checklist

  • This PR only fixes typos or documentation and needs no accepted issue.
  • An AI tool wrote or helped write this change. Tool: Claude Code

🤖 Generated with Claude Code

getNextBestRegionUrl threw when the cached region list had expired and
the region settings endpoint was unreachable. The old list is still a
better choice than a failed connection. A cancel or a rejected token
(401) still throws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lukasIO lukasIO self-assigned this Nov 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR bumps

  • livekit-client: patch

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
dist/livekit-client.esm.mjs 118.5 KB (+0.08% 🔺)
dist/livekit-client.umd.js 127.99 KB (+0.04% 🔺)
dist/core/core.mjs 79.85 KB (+0.05% 🔺)

This branch has not been deployed

No deployments
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.

2 participants