fix: Quit when the context is canceled in madmin (#9264)

This commit is contained in:
Harshavardhana 2020-04-06 17:50:14 -07:00 committed by GitHub
parent 91f21ddc47
commit 928f5b0564
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -367,12 +367,11 @@ func (adm AdminClient) executeMethod(ctx context.Context, method string, reqData
// Initiate the request. // Initiate the request.
res, err = adm.do(req) res, err = adm.do(req)
if err != nil { if err != nil {
// For supported http requests errors verify. if err == context.Canceled || err == context.DeadlineExceeded {
if isHTTPReqErrorRetryable(err) { return nil, err
continue // Retry.
} }
// For other errors, return here no need to retry. // retry all network errors.
return nil, err continue
} }
// For any known successful http status, return quickly. // For any known successful http status, return quickly.
@ -413,6 +412,12 @@ func (adm AdminClient) executeMethod(ctx context.Context, method string, reqData
break break
} }
// Return an error when retry is canceled or deadlined
if e := retryCtx.Err(); e != nil {
return nil, e
}
return res, err return res, err
} }

View File

@ -1,5 +1,5 @@
/* /*
* MinIO Cloud Storage, (C) 2019 MinIO, Inc. * MinIO Cloud Storage, (C) 2019-2020 MinIO, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -98,7 +98,12 @@ func (adm AdminClient) newRetryTimer(ctx context.Context, maxRetry int, unit tim
defer close(attemptCh) defer close(attemptCh)
for i := 0; i < maxRetry; i++ { for i := 0; i < maxRetry; i++ {
// Attempts start from 1. // Attempts start from 1.
attemptCh <- i + 1 select {
case attemptCh <- i + 1:
case <-ctx.Done():
// Stop the routine.
return
}
select { select {
case <-time.After(exponentialBackoffWait(i)): case <-time.After(exponentialBackoffWait(i)):