diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 8a1927a39ca..f3cfd99e75e 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -3,3 +3,4 @@ ### SDK Enhancements ### SDK Bugs +* `aws/request`: Fix shouldRetry behavior for nested errors ([#3017](https://github.com/aws/aws-sdk-go/pull/3017)) diff --git a/aws/request/retryer.go b/aws/request/retryer.go index 356e5d9d887..478bae0785b 100644 --- a/aws/request/retryer.go +++ b/aws/request/retryer.go @@ -177,7 +177,7 @@ func shouldRetryError(origErr error) bool { origErr := err.OrigErr() var shouldRetry bool if origErr != nil { - shouldRetry := shouldRetryError(origErr) + shouldRetry = shouldRetryError(origErr) if err.Code() == "RequestError" && !shouldRetry { return false } diff --git a/aws/request/retryer_test.go b/aws/request/retryer_test.go index 659e0fa3e39..8940a241874 100644 --- a/aws/request/retryer_test.go +++ b/aws/request/retryer_test.go @@ -76,7 +76,7 @@ func TestIsErrorRetryable(t *testing.T) { }, { Err: awserr.New(ErrCodeSerialization, "some error", errors.New("blah")), - Retryable: false, + Retryable: true, }, { Err: awserr.New("SomeError", "some error", nil), diff --git a/service/s3/s3manager/download_test.go b/service/s3/s3manager/download_test.go index a1700d8559c..a3a1e05aca8 100644 --- a/service/s3/s3manager/download_test.go +++ b/service/s3/s3manager/download_test.go @@ -2,6 +2,7 @@ package s3manager_test import ( "bytes" + "encoding/xml" "fmt" "io" "io/ioutil" @@ -101,9 +102,19 @@ func dlLoggingSvcNoContentRangeLength(data []byte, states []int) (*s3.S3, *[]str names = append(names, r.Operation.Name) + var body io.Reader + if states[index] < 400 { + body = bytes.NewReader(data[:]) + } else { + var buffer bytes.Buffer + encoder := xml.NewEncoder(&buffer) + _ = encoder.Encode(&mockErrorResponse) + body = &buffer + } + r.HTTPResponse = &http.Response{ StatusCode: states[index], - Body: ioutil.NopCloser(bytes.NewReader(data[:])), + Body: ioutil.NopCloser(body), Header: http.Header{}, } index++ @@ -840,3 +851,12 @@ func (b *badReader) Read(p []byte) (int, error) { return len(p), b.err } + +var mockErrorResponse = struct { + XMLName xml.Name `xml:"Error"` + Code string `xml:"Code"` + Message string `xml:"Message"` +}{ + Code: "MOCK_S3_ERROR_CODE", + Message: "Mocked S3 Error Message", +}