From e3ac4035b9c7bececc2ebabb1abab66d0dd35518 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 12 Jun 2024 01:13:12 -0700 Subject: [PATCH] decrement requests inqueue correctly after the request is processed (#19918) --- cmd/handler-api.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/handler-api.go b/cmd/handler-api.go index 7b5942a25..ad9d5903b 100644 --- a/cmd/handler-api.go +++ b/cmd/handler-api.go @@ -323,10 +323,9 @@ func maxClients(f http.HandlerFunc) http.HandlerFunc { } globalHTTPStats.addRequestsInQueue(1) - defer globalHTTPStats.addRequestsInQueue(-1) - pool, deadline := globalAPIConfig.getRequestsPool() if pool == nil { + globalHTTPStats.addRequestsInQueue(-1) f.ServeHTTP(w, r) return } @@ -334,6 +333,7 @@ func maxClients(f http.HandlerFunc) http.HandlerFunc { // No deadline to wait, there is nothing to queue // perform the API call immediately. if deadline <= 0 { + globalHTTPStats.addRequestsInQueue(-1) f.ServeHTTP(w, r) return } @@ -349,12 +349,14 @@ func maxClients(f http.HandlerFunc) http.HandlerFunc { select { case pool <- struct{}{}: defer func() { <-pool }() + globalHTTPStats.addRequestsInQueue(-1) if contextCanceled(ctx) { w.WriteHeader(499) return } f.ServeHTTP(w, r) case <-deadlineTimer.C: + globalHTTPStats.addRequestsInQueue(-1) if contextCanceled(ctx) { w.WriteHeader(499) return @@ -364,6 +366,7 @@ func maxClients(f http.HandlerFunc) http.HandlerFunc { errorCodes.ToAPIErr(ErrTooManyRequests), r.URL) case <-r.Context().Done(): + globalHTTPStats.addRequestsInQueue(-1) // When the client disconnects before getting the S3 handler // status code response, set the status code to 499 so this request // will be properly audited and traced.