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

Fix shouldRetry behavior for nested errors #3017

Merged
merged 4 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 1 addition & 1 deletion aws/request/retryer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion aws/request/retryer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
22 changes: 21 additions & 1 deletion service/s3/s3manager/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package s3manager_test

import (
"bytes"
"encoding/xml"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -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++
Expand Down Expand Up @@ -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",
}