From c7209ef2319f0ec2e8d0fd49df38d9a6d0d089a0 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 13 May 2017 19:53:24 +0200 Subject: [PATCH] api: Failed call retry with region only when http.StatusBadRequest. Fixes https://github.com/minio/minio-go/issues/677 --- vendor/src/github.com/minio/minio-go/api-put-bucket.go | 2 +- .../github.com/minio/minio-go/api-put-object-common.go | 10 ++++++---- vendor/src/github.com/minio/minio-go/api.go | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/vendor/src/github.com/minio/minio-go/api-put-bucket.go b/vendor/src/github.com/minio/minio-go/api-put-bucket.go index 001da6de3..ab3f355f5 100644 --- a/vendor/src/github.com/minio/minio-go/api-put-bucket.go +++ b/vendor/src/github.com/minio/minio-go/api-put-bucket.go @@ -89,7 +89,7 @@ func (c Client) MakeBucket(bucketName string, location string) (err error) { if resp.StatusCode != http.StatusOK { err := httpRespToErrorResponse(resp, bucketName, "") errResp := ToErrorResponse(err) - if errResp.Code == "InvalidRegion" && errResp.Region != "" { + if resp.StatusCode == http.StatusBadRequest && errResp.Region != "" { // Fetch bucket region found in headers // of S3 error response, attempt bucket // create again. diff --git a/vendor/src/github.com/minio/minio-go/api-put-object-common.go b/vendor/src/github.com/minio/minio-go/api-put-object-common.go index 68a459f4a..d69447317 100644 --- a/vendor/src/github.com/minio/minio-go/api-put-object-common.go +++ b/vendor/src/github.com/minio/minio-go/api-put-object-common.go @@ -157,11 +157,13 @@ func hashCopyN(hashAlgorithms map[string]hash.Hash, hashSums map[string][]byte, return 0, err } } - - for k, v := range hashAlgorithms { - hashSums[k] = v.Sum(nil) + if err == nil && size == partSize { + for k, v := range hashAlgorithms { + hashSums[k] = v.Sum(nil) + } + return size, nil } - return size, err + return 0, ErrUnexpectedEOF(size, partSize, "", "") } // getUploadID - fetch upload id if already present for an object name diff --git a/vendor/src/github.com/minio/minio-go/api.go b/vendor/src/github.com/minio/minio-go/api.go index a563a18d4..a7ff96a03 100644 --- a/vendor/src/github.com/minio/minio-go/api.go +++ b/vendor/src/github.com/minio/minio-go/api.go @@ -553,7 +553,7 @@ func (c Client) executeMethod(method string, metadata requestMetadata) (res *htt // Bucket region if set in error response and the error // code dictates invalid region, we can retry the request // with the new region. - if errResponse.Code == "InvalidRegion" && errResponse.Region != "" { + if res.StatusCode == http.StatusBadRequest && errResponse.Region != "" { c.bucketLocCache.Set(metadata.bucketName, errResponse.Region) continue // Retry. }