Repository navigation
fix(upstream): cap the number of anonymous exits tried per request - #127
Merged
jasonxu114514 merged 1 commit intoOct 20, 2026
Merged
Conversation
doAnonymousUpstream used limit = len(pool), so a request that every exit rejects (403/429) walked the whole proxyfile, up to two legs per exit, before failing. With a ~24 exit proxyfile this showed up as requests with 19-77 attempts and 200-660s of wall time, all ending in a 403/429 or a client cancel. Cap the static exit walk at 8. The #pool rule is unchanged: when a pool entry is present the limit still rises to retry.max_attempts, so a single rotating #pool entry keeps its per-attempt fresh IP.
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.
Problem
doAnonymousUpstreamsetslimit = g.anonymous.Len(), so a request that every exit rejects (403/429) walks the entire proxyfile, with up to two legs per exit (v1 lane, then/inference), before it gives up.Observed on a long-running instance with a ~24-exit proxyfile (log:
request_routedevents, 2104 anonymous requests before the change):After capping the walk at 8 exits, the same instance served 180 anonymous requests with a maximum of 7 attempts and no request above 8.
Change
maxAnonymousExits = 8and usemin(Len(), maxAnonymousExits)as the static-exit limit#poolrule is untouched: when a pool entry is present the limit still rises toretry.max_attempts, so a single rotating#poolentry keeps its fresh-IP-per-attempt behaviour2 lines of logic plus comments, in
internal/gateway/upstream.goonly.Not included / open points
refresh.go(the availability probe) has its own copy of the old limit formula and is deliberately left alone to keep this change minimal. Happy to apply the same cap there if you want it.main, so none are added;gofmt -l,go vet ./...andgo build -trimpath ./cmd/opencode2apipass locally.