Skip to content

Commit e6866ff

Browse files
committed
feat(auth): add refresh backoff for ineffective token updates
- Introduced `refreshIneffectiveBackoff` to prevent tight-looping in auto-refresh when token refresh fails to update expiry. - Adjusted refresh logic to apply backoff when `shouldRefresh` evaluates true. Closes: router-for-me#2830
1 parent 8f4a4ea commit e6866ff

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

sdk/cliproxy/auth/conductor.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@ const (
6464
refreshMaxConcurrency = 16
6565
refreshPendingBackoff = time.Minute
6666
refreshFailureBackoff = 5 * time.Minute
67-
quotaBackoffBase = time.Second
68-
quotaBackoffMax = 30 * time.Minute
67+
// refreshIneffectiveBackoff throttles refresh attempts when an executor returns
68+
// success but the auth still evaluates as needing refresh (e.g. token expiry
69+
// wasn't updated). Without this guard, the auto-refresh loop can tight-loop and
70+
// burn CPU at idle.
71+
refreshIneffectiveBackoff = 30 * time.Second
72+
quotaBackoffBase = time.Second
73+
quotaBackoffMax = 30 * time.Minute
6974
)
7075

7176
var quotaCooldownDisabled atomic.Bool
@@ -3240,6 +3245,9 @@ func (m *Manager) refreshAuth(ctx context.Context, id string) {
32403245
updated.NextRefreshAfter = time.Time{}
32413246
updated.LastError = nil
32423247
updated.UpdatedAt = now
3248+
if m.shouldRefresh(updated, now) {
3249+
updated.NextRefreshAfter = now.Add(refreshIneffectiveBackoff)
3250+
}
32433251
_, _ = m.Update(ctx, updated)
32443252
}
32453253

0 commit comments

Comments
 (0)