Skip to content

Commit

Permalink
Merge pull request #171 from github/meiji163/check-expire-at-zero
Browse files Browse the repository at this point in the history
Check expire at zero for throttled apps
  • Loading branch information
meiji163 authored Sep 25, 2024
2 parents 2acc13e + cc5cb93 commit 336333c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/throttle/throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ func (throttler *Throttler) expireThrottledApps() {
now := time.Now()
for appName, item := range throttler.throttledApps.Items() {
appThrottle := item.Object.(*base.AppThrottle)
if appThrottle.ExpireAt.Before(now) {
if !appThrottle.ExpireAt.IsZero() && appThrottle.ExpireAt.Before(now) {
throttler.UnthrottleApp(appName)
}
}
Expand Down Expand Up @@ -530,12 +530,12 @@ func (throttler *Throttler) ThrottleApp(appName string, expireAt time.Time, rati
}
appThrottle = base.NewAppThrottle(expireAt, ratio)
}

if expireAt.IsZero() {
//If expires at is zero, update the store to never expire the throttle
throttler.throttledApps.Set(appName, appThrottle, -1)
} else if now.Before(appThrottle.ExpireAt) {
throttler.throttledApps.Set(appName, appThrottle, cache.DefaultExpiration)
throttler.throttledApps.Set(appName, appThrottle, cache.DefaultExpiration)
} else {
throttler.UnthrottleApp(appName)
}
Expand All @@ -552,7 +552,7 @@ func (throttler *Throttler) IsAppThrottled(appName, storeName string) bool {
for _, key := range keys {
if object, found := throttler.throttledApps.Get(key); found {
appThrottle := object.(*base.AppThrottle)
if appThrottle.ExpireAt.Before(time.Now()) {
if !appThrottle.ExpireAt.IsZero() && appThrottle.ExpireAt.Before(time.Now()) {
// throttling cleanup hasn't purged yet, but it is expired
continue
}
Expand Down

0 comments on commit 336333c

Please sign in to comment.