mirror of
https://github.com/chenyme/grok2api.git
synced 2026-12-05 08:01:07 +00:00
fix(gateway): cool down Build accounts after unknown 403
This commit is contained in:
1 parent
5e5ad75556
commit
a88cd8808c
2 files changed
+6
-6
No files matched your search
@@ -1554,7 +1554,7 @@ attemptLoop:
|
||||
} else if s.providers.SupportsCredentialRefresh(credential.Provider) && lastFailure.CredentialRejected {
|
||||
failureHandled = s.markReauthRequired(ctx, input.RequestID, credential, fmt.Sprintf("%s credential rejected", credential.Provider))
|
||||
}
|
||||
if lastFailure.AccountScoped && !failureHandled {
|
||||
if !failureHandled && (lastFailure.AccountScoped || credential.Provider == accountdomain.ProviderBuild && response.StatusCode == http.StatusForbidden) {
|
||||
s.selector.MarkFailure(ctx, credential, response.StatusCode, retryAfter)
|
||||
} else if !lastFailure.AccountScoped && response.StatusCode >= http.StatusInternalServerError {
|
||||
// Provider-wide 5xx responses should rotate this request and briefly
|
||||
|
||||
@@ -1963,7 +1963,7 @@ func TestParseFreeQuotaExhaustionCurrentBuildFreeLimit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGatewayUnknownBuildForbiddenTraversesAllAccountsWithoutCooldown(t *testing.T) {
|
||||
func TestGatewayUnknownBuildForbiddenTraversesAllAccountsWithCooldown(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
database, err := relational.OpenSQLite(ctx, filepath.Join(t.TempDir(), "systemic-forbidden.db"))
|
||||
if err != nil {
|
||||
@@ -2033,8 +2033,8 @@ func TestGatewayUnknownBuildForbiddenTraversesAllAccountsWithoutCooldown(t *test
|
||||
if getErr != nil {
|
||||
t.Fatal(getErr)
|
||||
}
|
||||
if observed.FailureCount != 0 || observed.CooldownUntil != nil || observed.AuthStatus != account.AuthStatusActive {
|
||||
t.Fatalf("account %d was penalized after unknown 403: %#v", credential.ID, observed)
|
||||
if observed.FailureCount == 0 || observed.CooldownUntil == nil || observed.AuthStatus != account.AuthStatusActive {
|
||||
t.Fatalf("account %d was not cooled down after unknown Build 403: %#v", credential.ID, observed)
|
||||
}
|
||||
}
|
||||
logs, total, err := auditRepo.List(ctx, 0, 10)
|
||||
@@ -3946,8 +3946,8 @@ func TestGatewayUnknownBuildForbiddenRotatesWithoutPenalizingAccount(t *testing.
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if observed.AuthStatus != account.AuthStatusActive || observed.FailureCount != 0 || observed.CooldownUntil != nil {
|
||||
t.Fatalf("unknown 403 penalized first account: %#v", observed)
|
||||
if observed.AuthStatus != account.AuthStatusActive || observed.FailureCount == 0 || observed.CooldownUntil == nil {
|
||||
t.Fatalf("unknown Build 403 did not cool down first account: %#v", observed)
|
||||
}
|
||||
candidates, err := accountRepo.ListRoutingCandidates(ctx, account.ProviderBuild, 0, model, "")
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user