mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-11-03 07:44:13 +00:00
fix(session): keep cooldown trackers and trim stale chunks by key
Cleanup evicted a refresh tracker by last attempt time alone. A tracker could leave its cooldown early. Cleanup now also requires the cooldown to be over. The stale chunk trim deleted an index range derived from the chunk count. A sparse key set kept stale high keys and failed the read. The trim now deletes every key at or above token_total.
This commit is contained in:
@@ -823,13 +823,16 @@ func (rc *RefreshCoordinator) cleanupRoutine() {
|
||||
// cleanupStaleEntries removes outdated tracking entries. Lock-free iteration
|
||||
// via sync.Map.Range; safe to race with concurrent reads/writes.
|
||||
func (rc *RefreshCoordinator) cleanupStaleEntries() {
|
||||
cutoff := time.Now().Add(-2 * rc.config.RefreshAttemptWindow).UnixNano()
|
||||
now := time.Now()
|
||||
cutoff := now.Add(-2 * rc.config.RefreshAttemptWindow).UnixNano()
|
||||
nowNano := now.UnixNano()
|
||||
rc.sessionRefreshAttempts.Range(func(key, value interface{}) bool {
|
||||
tracker := trackerFromMapValue(value)
|
||||
if tracker == nil {
|
||||
return true
|
||||
}
|
||||
if tracker.stateOf().lastAttemptNano < cutoff {
|
||||
st := tracker.stateOf()
|
||||
if st.lastAttemptNano < cutoff && st.cooldownEndNano <= nowNano {
|
||||
// Compare-and-delete to avoid evicting a tracker that was just
|
||||
// re-used by a concurrent caller. We compare by pointer identity.
|
||||
rc.sessionRefreshAttempts.CompareAndDelete(key, value)
|
||||
|
||||
Reference in New Issue
Block a user