Skip to content

Commit e8c33cb

Browse files
committed
fix unthrottle logic
1 parent 028dce2 commit e8c33cb

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

pkg/http/api.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,21 @@ response:
273273
api.respondGeneric(w, r, err)
274274
}
275275

276-
// ThrottleApp unthrottles given app.
276+
// UnthrottleApp unthrottles given app.
277277
func (api *APIImpl) UnthrottleApp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
278278
appName := ps.ByName("app")
279-
err := api.consensusService.UnthrottleApp(appName)
280-
281-
api.respondGeneric(w, r, err)
279+
appWithStorePrefix := appName + "/"
280+
281+
for app := range api.consensusService.ThrottledAppsMap() {
282+
if app == appName || strings.HasPrefix(app, appWithStorePrefix) {
283+
err := api.consensusService.UnthrottleApp(app)
284+
if err != nil {
285+
api.respondGeneric(w, r, err)
286+
return
287+
}
288+
}
289+
}
290+
api.respondGeneric(w, r, nil)
282291
}
283292

284293
// ThrottledApps returns a snapshot of all currently throttled apps

pkg/throttle/throttler.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,24 +524,19 @@ func (throttler *Throttler) ThrottleApp(appName string, expireAt time.Time, rati
524524
}
525525

526526
func (throttler *Throttler) UnthrottleApp(appName string) {
527-
appWithStore := appName + "/"
528-
for app, _ := range throttler.throttledApps.Items() {
529-
if app == appName || strings.HasPrefix(app, appWithStore) {
530-
throttler.throttledApps.Delete(app)
531-
}
532-
}
527+
throttler.throttledApps.Delete(appName)
533528
}
534529

535530
func (throttler *Throttler) IsAppThrottled(appName, storeName string) bool {
536531
appWithStore := fmt.Sprintf("%s/%s", appName, storeName)
537532
keys := []string{appWithStore, appName}
538-
// check if app is throttled globally
533+
// check if app is throttled for this store or globally
539534
for _, key := range keys {
540535
if object, found := throttler.throttledApps.Get(key); found {
541536
appThrottle := object.(*base.AppThrottle)
542537
if appThrottle.ExpireAt.Before(time.Now()) {
543538
// throttling cleanup hasn't purged yet, but it is expired
544-
return false
539+
continue
545540
}
546541
// handle ratio
547542
if rand.Float64() < appThrottle.Ratio {

0 commit comments

Comments
 (0)