-
Notifications
You must be signed in to change notification settings - Fork 433
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add s3 connection reset retries (#1137)
* Add s3 connection reset retries * Add test
- Loading branch information
1 parent
1a00965
commit 8e3c68a
Showing
3 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package s3 | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go/aws/request" | ||
) | ||
|
||
func NewConnResetRetryer(baseRetryer request.Retryer) *ConnResetRetryer { | ||
return &ConnResetRetryer{ | ||
baseRetryer, | ||
} | ||
} | ||
|
||
type ConnResetRetryer struct { | ||
request.Retryer | ||
} | ||
|
||
func (r ConnResetRetryer) ShouldRetry(req *request.Request) bool { | ||
if req.Error != nil && strings.Contains(req.Error.Error(), "connection reset by peer") { | ||
return true | ||
} | ||
|
||
return r.Retryer.ShouldRetry(req) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package s3 | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"os" | ||
"syscall" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws/client" | ||
"github.com/aws/aws-sdk-go/aws/request" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConnResetRetryerRetry(t *testing.T) { | ||
retryer := NewConnResetRetryer(client.DefaultRetryer{}) | ||
err := &net.OpError{ | ||
Op: "mock", | ||
Net: "mock", | ||
Source: &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 1234}, | ||
Addr: &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 12340}, | ||
Err: &os.SyscallError{Syscall: "read", Err: syscall.ECONNRESET}, | ||
} | ||
|
||
req := &request.Request{ | ||
Error: err, | ||
} | ||
|
||
assert.True(t, retryer.ShouldRetry(req)) | ||
} | ||
|
||
func TestConnResetRetryerRandomError(t *testing.T) { | ||
retryer := NewConnResetRetryer(client.DefaultRetryer{}) | ||
req := &request.Request{ | ||
Error: fmt.Errorf("some strange unknown error"), | ||
} | ||
assert.False(t, retryer.ShouldRetry(req)) | ||
} | ||
|
||
func TestConnResetRetryerNoError(t *testing.T) { | ||
retryer := NewConnResetRetryer(client.DefaultRetryer{}) | ||
assert.False(t, retryer.ShouldRetry(&request.Request{})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters