Skip to content

Commit

Permalink
Conditionally retry HTTP calls for specific S3 errors (#799)
Browse files Browse the repository at this point in the history
When InvalidRegion or AuthorizationHeaderMalformed error is received from S3 server,
update bucket region cache and retry the same ReST call with returned region.

Fixes #795 and #764
  • Loading branch information
kannappanr authored and deekoder committed Aug 29, 2017
1 parent 8cf0454 commit dcd84a9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,14 @@ func (c Client) executeMethod(method string, metadata requestMetadata) (res *htt
// Additionally we should only retry if bucketLocation and custom
// region is empty.
if metadata.bucketLocation == "" && c.region == "" {
if res.StatusCode == http.StatusBadRequest && errResponse.Region != "" {
c.bucketLocCache.Set(metadata.bucketName, errResponse.Region)
continue // Retry.
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.
}
}
}
}

Expand Down

0 comments on commit dcd84a9

Please sign in to comment.