diff --git a/pkg/madmin/api.go b/pkg/madmin/api.go index a0d902b47..301e4350b 100644 --- a/pkg/madmin/api.go +++ b/pkg/madmin/api.go @@ -367,12 +367,11 @@ func (adm AdminClient) executeMethod(ctx context.Context, method string, reqData // Initiate the request. res, err = adm.do(req) if err != nil { - // For supported http requests errors verify. - if isHTTPReqErrorRetryable(err) { - continue // Retry. + if err == context.Canceled || err == context.DeadlineExceeded { + return nil, err } - // For other errors, return here no need to retry. - return nil, err + // retry all network errors. + continue } // For any known successful http status, return quickly. @@ -413,6 +412,12 @@ func (adm AdminClient) executeMethod(ctx context.Context, method string, reqData break } + + // Return an error when retry is canceled or deadlined + if e := retryCtx.Err(); e != nil { + return nil, e + } + return res, err } diff --git a/pkg/madmin/retry.go b/pkg/madmin/retry.go index 099de381a..5e8b9b251 100644 --- a/pkg/madmin/retry.go +++ b/pkg/madmin/retry.go @@ -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"); * 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) for i := 0; i < maxRetry; i++ { // Attempts start from 1. - attemptCh <- i + 1 + select { + case attemptCh <- i + 1: + case <-ctx.Done(): + // Stop the routine. + return + } select { case <-time.After(exponentialBackoffWait(i)):