Skip to content

Commit

Permalink
Retry list requests for InvalidRegion error responses
Browse files Browse the repository at this point in the history
Update metadata.bucketLocation with the correct region from the error response.

Fixes minio/mc#2570
  • Loading branch information
Praveenrajmani committed Feb 12, 2019
1 parent 34f2b94 commit 5c00564
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,22 @@ func (c Client) executeMethod(ctx context.Context, method string, metadata reque
req, err = c.newRequest(method, metadata)
if err != nil {
errResponse := ToErrorResponse(err)
if errResponse.Code == "AuthorizationHeaderMalformed" || errResponse.Code == "InvalidRegion" {
if errResponse.Region != "" {
metadata.bucketLocation = errResponse.Region
if metadata.bucketName != "" {
// Gather Cached location only if bucketName is present.
if _, cachedLocationError := c.bucketLocCache.Get(metadata.bucketName); cachedLocationError != false {
c.bucketLocCache.Set(metadata.bucketName, errResponse.Region)

continue // Retry.
}
}
metadata.bucketLocation = errResponse.Region
continue
}
}

if isS3CodeRetryable(errResponse.Code) {
continue // Retry.
}
Expand Down Expand Up @@ -639,12 +655,16 @@ func (c Client) executeMethod(ctx context.Context, method string, metadata reque
// region is empty.
if metadata.bucketLocation == "" && c.region == "" {
if errResponse.Code == "AuthorizationHeaderMalformed" || errResponse.Code == "InvalidRegion" {
if metadata.bucketName != "" && errResponse.Region != "" {
// Gather Cached location only if bucketName is present.
if _, cachedLocationError := c.bucketLocCache.Get(metadata.bucketName); cachedLocationError != false {
c.bucketLocCache.Set(metadata.bucketName, errResponse.Region)
continue // Retry.
if errResponse.Region != "" {
if metadata.bucketName != "" {
// Gather Cached location only if bucketName is present.
if _, cachedLocationError := c.bucketLocCache.Get(metadata.bucketName); cachedLocationError != false {
c.bucketLocCache.Set(metadata.bucketName, errResponse.Region)
continue // Retry.
}
}
metadata.bucketLocation = errResponse.Region
continue
}
}
}
Expand Down

0 comments on commit 5c00564

Please sign in to comment.