Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry list requests for InvalidRegion error responses #1074

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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