修复误判死

This commit is contained in:
2026-07-06 15:52:09 +08:00
parent c25e162841
commit d3a479ed76
+20 -8
View File
@@ -966,15 +966,27 @@ func (s *TokenService) RefreshGrokLiveness(ctx context.Context) {
if it.Pool != "grok" || it.Dead || it.Status == "disabled" || strings.TrimSpace(it.Value) == "" { if it.Pool != "grok" || it.Dead || it.Status == "disabled" || strings.TrimSpace(it.Value) == "" {
continue continue
} }
sub, serr := s.grok.FetchSubscription(ctx, it.Value) // A grok sso can momentarily 401 (upstream blip / proxy hiccup / anti-bot)
// while still being fully valid, so a single auth failure must never kill a
// live account. Retry the subscription probe up to 3 times on 401/403; only
// if all 3 attempts still return ErrAuth do we treat the session as dead.
var sub *grok.Subscription
var serr error
for attempt := 1; attempt <= 3; attempt++ {
sub, serr = s.grok.FetchSubscription(ctx, it.Value)
if serr == nil || !errors.Is(serr, grok.ErrAuth) {
break
}
if attempt < 3 {
time.Sleep(2 * time.Second)
}
}
if serr != nil { if serr != nil {
// Any probe error — including 401/403 (ErrAuth) — is treated as if errors.Is(serr, grok.ErrAuth) {
// transient: leave the account as-is and retry next tick. A grok sso // 3 consecutive 401/403 → the sso session is genuinely dead.
// can momentarily 401 (upstream blip / proxy hiccup / anti-bot) while _, _ = s.tokens.Update(ctx, "grok", it.ID, map[string]any{"status": "disabled", "dead": true})
// still being fully valid, so a single auth failure must NOT kill a }
// live account. Genuine membership loss is still caught below via an continue // other transient upstream error → leave as-is, retry next tick
// INACTIVE/empty subscription (!sub.Member).
continue
} }
if sub == nil || !sub.Member { if sub == nil || !sub.Member {
// no ACTIVE subscription (INACTIVE / empty) → membership lapsed → dead. // no ACTIVE subscription (INACTIVE / empty) → membership lapsed → dead.