Repository navigation
Conversation
The proxy reads the Redis catalog on every request with no fallback, so a brief Redis blip 5xx-ed all traffic to already-running sandboxes even though the VM and its routing record were fine. Add CachingSandboxCatalog: an in-memory short-TTL (default 60s) route cache consulted only on a transient error; a fresh success refreshes it, a definitive ErrSandboxNotFound is never served from cache and evicts, DeleteSandbox evicts. Wire it in client-proxy. Adds unit tests. Refs e2b-dev#3788
… hits/stale - GetSandbox fallback now returns the backing error untouched when the caller context is done, instead of serving a route for a request that is already gone. - Count fallback use (result=hit when a fresh entry is served, stale when nothing fresh remains and the error stands) via a new clientproxy.catalog.cache.fallback.total counter, so a flap outliving the window is visible rather than silent. - Wire the client-proxy meter into the cache; nil meter stays a no-op. - Tests for the caller-cancelled path; existing cache tests pass under -race.
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: AdaAibaby.
|
This branch has not been deployed
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.
What
client-proxyresolves every request's route from the Redis catalog (catalogResolution→GetSandbox) with a 1s timeout and no fallback. While Redis is briefly unreachable, requests to already-running sandboxes fail even though the VM and its routing record (TTL = full lifetime) are fine.This adds a small in-memory route cache that is consulted only when the backing catalog returns a transient error, so a short Redis blip no longer breaks routing for running sandboxes. Refs #3788.
How
CachingSandboxCatalogdecorates anySandboxesCatalog:maxStale(default 60s), else return the error;ErrSandboxNotFound→ never served from cache (a stale route would mis-route to a dead worker); evicts the entry;DeleteSandbox→ evicts; cache is size-capped (50k) with oldest-first eviction.Routing records only change on resume/worker-move, so a ≤60s stale route during a flap is a good trade against failing live traffic, and correctness is bounded: no stale not-found, bounded staleness, and a Redis error is already distinct from
redis.Nil.Fallback use is counted (
clientproxy.catalog.cache.fallback.total,result=hitwhen a fresh entry is served,result=stalewhen nothing fresh remains and the error stands) so the cache's effect — and a flap that outlives the window — is visible on dashboards rather than silent. Wired inclient-proxy/main.go; a nil meter is a no-op.Scope
This is a read-side safety net, deliberately minimal: no new steady-state load (the cache only does work on an error path), no behavior change on the happy path, and nothing resurrected after delete/not-found. It does not touch the write side.
Test
catalog_cache_test.go: serves cached route on transient error; never serves not-found from cache (and evicts); propagates error once stale beyond the window; evicts on delete; returns the error without serving cache when the caller context is cancelled.go test -race ./packages/shared/pkg/sandbox-catalog/passes (the cache tests; the Redis-backed tests need a live instance);client-proxybuilds.