Skip to content

Commit

Permalink
Add s3 connection reset retries
Browse files Browse the repository at this point in the history
  • Loading branch information
usernamedt committed Oct 28, 2021
1 parent 1a00965 commit 8c939f7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions pkg/storages/s3/retryer.go
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: baseRetryer,
}
}

type ConnResetRetryer struct {
baseRetryer 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.baseRetryer.ShouldRetry(req)
}
2 changes: 1 addition & 1 deletion pkg/storages/s3/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func getDefaultConfig(settings map[string]string) *aws.Config {
// most services. If you want to implement custom retry logic, you can implement the
// request.Retryer interface.
config := defaults.Get().Config.WithRegion(settings[RegionSetting])
config = request.WithRetryer(config, client.DefaultRetryer{NumMaxRetries: MaxRetries})
config = request.WithRetryer(config, NewConnResetRetryer(client.DefaultRetryer{NumMaxRetries: MaxRetries}))

if logLevel, ok := settings[LogLevel]; ok {
config = config.WithLogLevel(func(s string) aws.LogLevelType {
Expand Down

0 comments on commit 8c939f7

Please sign in to comment.