From b4abafbc9cb05169811b6fa060f65c037997a19b Mon Sep 17 00:00:00 2001 From: Tanveer Gill Date: Wed, 3 Jan 2024 18:58:12 -0800 Subject: [PATCH] Fix wait time based deadline calculation (#3120) ### Description of change ##### Checklist - [x] Tested in playground or other setup - [ ] Screenshot (Grafana) from playground added to PR for 15+ minute run - [ ] Documentation is changed or added - [ ] Tests and/or benchmarks are included - [ ] Breaking changes --- .../concurrency-limiter/global-token-counter.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/dmap-funcs/concurrency-limiter/global-token-counter.go b/pkg/dmap-funcs/concurrency-limiter/global-token-counter.go index 766c717a3d..87a4a28f4b 100644 --- a/pkg/dmap-funcs/concurrency-limiter/global-token-counter.go +++ b/pkg/dmap-funcs/concurrency-limiter/global-token-counter.go @@ -410,9 +410,6 @@ func (gtc *GlobalTokenCounter) takeN(key string, stateBytes, argBytes []byte) ([ } else { waitTime = MinimumWaitTime } - if waitTime < MinimumWaitTime { - waitTime = MinimumWaitTime - } if requestQueued != nil { if requestQueued.NumRetries >= 5 { // override wait time if the request has been retried more than 5 times @@ -424,6 +421,12 @@ func (gtc *GlobalTokenCounter) takeN(key string, stateBytes, argBytes []byte) ([ waitTime = requestQueued.WaitFor.AsDuration() * 2 } } + if waitTime < MinimumWaitTime { + waitTime = MinimumWaitTime + } + if waitTime > MaximumWaitTime { + waitTime = MaximumWaitTime + } var requestsInflight []*tokencounterv1.Request var tokensInflight float64