mirror of
https://github.com/minio/minio.git
synced 2025-02-23 03:22:30 -05:00
return appropriate error upon reaching maxClients() (#19669)
This commit is contained in:
parent
b9bdc17465
commit
981497799a
@ -1478,7 +1478,7 @@ var errorCodes = errorCodeMap{
|
|||||||
ErrTooManyRequests: {
|
ErrTooManyRequests: {
|
||||||
Code: "TooManyRequests",
|
Code: "TooManyRequests",
|
||||||
Description: "Deadline exceeded while waiting in incoming queue, please reduce your request rate",
|
Description: "Deadline exceeded while waiting in incoming queue, please reduce your request rate",
|
||||||
HTTPStatusCode: http.StatusServiceUnavailable,
|
HTTPStatusCode: http.StatusTooManyRequests,
|
||||||
},
|
},
|
||||||
ErrUnsupportedMetadata: {
|
ErrUnsupportedMetadata: {
|
||||||
Code: "InvalidArgument",
|
Code: "InvalidArgument",
|
||||||
|
@ -321,13 +321,21 @@ func maxClients(f http.HandlerFunc) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
globalHTTPStats.addRequestsInQueue(1)
|
||||||
|
defer globalHTTPStats.addRequestsInQueue(-1)
|
||||||
|
|
||||||
pool, deadline := globalAPIConfig.getRequestsPool()
|
pool, deadline := globalAPIConfig.getRequestsPool()
|
||||||
if pool == nil {
|
if pool == nil {
|
||||||
f.ServeHTTP(w, r)
|
f.ServeHTTP(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
globalHTTPStats.addRequestsInQueue(1)
|
// No deadline to wait, there is nothing to queue
|
||||||
|
// perform the API call immediately.
|
||||||
|
if deadline <= 0 {
|
||||||
|
f.ServeHTTP(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if tc, ok := r.Context().Value(mcontext.ContextTraceKey).(*mcontext.TraceCtxt); ok {
|
if tc, ok := r.Context().Value(mcontext.ContextTraceKey).(*mcontext.TraceCtxt); ok {
|
||||||
tc.FuncName = "s3.MaxClients"
|
tc.FuncName = "s3.MaxClients"
|
||||||
@ -336,25 +344,29 @@ func maxClients(f http.HandlerFunc) http.HandlerFunc {
|
|||||||
deadlineTimer := time.NewTimer(deadline)
|
deadlineTimer := time.NewTimer(deadline)
|
||||||
defer deadlineTimer.Stop()
|
defer deadlineTimer.Stop()
|
||||||
|
|
||||||
|
ctx := r.Context()
|
||||||
select {
|
select {
|
||||||
case pool <- struct{}{}:
|
case pool <- struct{}{}:
|
||||||
defer func() { <-pool }()
|
defer func() { <-pool }()
|
||||||
globalHTTPStats.addRequestsInQueue(-1)
|
if contextCanceled(ctx) {
|
||||||
|
w.WriteHeader(499)
|
||||||
|
return
|
||||||
|
}
|
||||||
f.ServeHTTP(w, r)
|
f.ServeHTTP(w, r)
|
||||||
case <-deadlineTimer.C:
|
case <-deadlineTimer.C:
|
||||||
|
if contextCanceled(ctx) {
|
||||||
|
w.WriteHeader(499)
|
||||||
|
return
|
||||||
|
}
|
||||||
// Send a http timeout message
|
// Send a http timeout message
|
||||||
writeErrorResponse(r.Context(), w,
|
writeErrorResponse(ctx, w,
|
||||||
errorCodes.ToAPIErr(ErrTooManyRequests),
|
errorCodes.ToAPIErr(ErrTooManyRequests),
|
||||||
r.URL)
|
r.URL)
|
||||||
globalHTTPStats.addRequestsInQueue(-1)
|
|
||||||
return
|
|
||||||
case <-r.Context().Done():
|
case <-r.Context().Done():
|
||||||
// When the client disconnects before getting the S3 handler
|
// When the client disconnects before getting the S3 handler
|
||||||
// status code response, set the status code to 499 so this request
|
// status code response, set the status code to 499 so this request
|
||||||
// will be properly audited and traced.
|
// will be properly audited and traced.
|
||||||
w.WriteHeader(499)
|
w.WriteHeader(499)
|
||||||
globalHTTPStats.addRequestsInQueue(-1)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user