failover: retry the same host when no fallback origin exists, and cover the Cloud API hosts - #723
Open
u9g wants to merge 2 commits into
Open
failover: retry the same host when no fallback origin exists, and cover the Cloud API hosts#723u9g wants to merge 2 commits into
u9g wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 3f51ac7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
u9g
force-pushed
the
jason/cloud-api-retry
branch
2 times, most recently
from
September 11, 2026 18:00
69eff5c to
d19c32b
Compare
A retryable failure with no untried origin left used to be surfaced after a single attempt. Retry it against the same origin instead, bounded by the existing attempt count and backoff. This matches the cross-region path, which already retries both transport errors and 5xx responses.
u9g
force-pushed
the
jason/cloud-api-retry
branch
from
September 11, 2026 18:01
d19c32b to
3f51ac7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A request to
cloud-api.livekit.iowas lost between Cloudflare and the origin on 2026-09-11: the edge acknowledged it, but no LiveKit system ever saw it, and the client waited out its full timeout. Every surrounding call succeeded, so a single retry would have recovered it.The SDK's failover loop could not help, for two reasons:
*.livekit.cloud, so acloud-api.livekit.iorequest always got exactly one attempt./settings/regionsreturns 404.What
Two commits, each test-first:
pickNextfinds no untried origin, a retryable failure (a thrown fetch error or an HTTP 5xx) now re-sends the request to the same host instead of surfacing it. Transport errors and 5xx are treated alike: a transport error can also mean the server executed the request and only the response was lost, so distinguishing them buys no idempotency safety, and cross-region failover already retries 5xx. Every attempt carries the sameX-Livekit-Request-Id, so the server can dedup a replay. Max attempts and backoff are unchanged; a 4xx is still terminal.isCloudApicheck matchescloud-api.livekit.ioandcloud-api.<env>.livekit.io(case-insensitively) and joinsisCloudin the attempts policy. A Cloud API host has a single origin, so the retry loop never fetches/settings/regionsfor it and goes straight to the same-host retry; otherwise every failed attempt would also pay the discovery timeout. The existing.livekit.cloudcheck is unchanged.Includes a patch changeset for
livekit-server-sdk.Behavior change
For cloud-api calls with a request timeout at or above
MIN_FAILOVER_TIMEOUT_SECONDS(5s, including the 10s default), a lost request or a 5xx now costs up toFAILOVER_MAX_ATTEMPTS(3) attempts with exponential backoff instead of failing after one. A truly dead or persistently erroring origin takes up to three times the per-attempt budget to surface. Requests with a shorter timeout keep getting a single attempt. For.livekit.cloudproject hosts, the same-host retry only engages once every discovered region has been tried, so their behavior is unchanged in practice.Mirrors livekit/server-sdk-go#1002.
Testing
pnpm exec vitest --environment node runinpackages/livekit-server-sdk: 8 files, 115 tests passing, including thetest/apiintegration suite against a locallivekit/test-servercontainer (LK_TEST_SERVER_URL).New tests, each confirmed failing before its implementation commit:
TwirpRPC.test.ts: "without a fallback origin, a transport error retries the same host", "without a fallback origin, a 5xx retries the same host", and "a Cloud API host retries without consulting region discovery" (asserts zero/settings/regionsfetches).failover.test.ts:cloud-api.livekit.io,cloud-api.staging.livekit.io, andCLOUD-API.LIVEKIT.IOget max attempts;cloud-api.example.comgets one.pnpm lintandprettier --checkare clean on the changed files (the 3 existing lint warnings are pre-existing and untouched).