From cc5cb93aa6c73f97ad1659e12e880924e42508f9 Mon Sep 17 00:00:00 2001 From: meiji163 Date: Tue, 24 Sep 2024 20:52:10 -0700 Subject: [PATCH] check expire at zero --- pkg/throttle/throttler.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/throttle/throttler.go b/pkg/throttle/throttler.go index e819f61..e0d103c 100644 --- a/pkg/throttle/throttler.go +++ b/pkg/throttle/throttler.go @@ -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) } } @@ -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) } @@ -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 }