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

Add retry to S3 connection reset errors #274

Merged
merged 1 commit into from
May 24, 2024
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
12 changes: 11 additions & 1 deletion plugins/indexing/pluginaws/aws_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package pluginaws

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/client"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
)

Expand All @@ -14,5 +16,13 @@ func NewSession() (*session.Session, error) {
}

func NewS3Config() (*aws.Config, error) {
return aws.NewConfig(), nil
cfg := aws.NewConfig()
request.WithRetryer(cfg, CustomRetryer{DefaultRetryer: client.DefaultRetryer{
NumMaxRetries: client.DefaultRetryerMaxNumRetries,
MinRetryDelay: client.DefaultRetryerMinRetryDelay,
MaxRetryDelay: client.DefaultRetryerMaxRetryDelay,
MinThrottleDelay: client.DefaultRetryerMinThrottleDelay,
MaxThrottleDelay: client.DefaultRetryerMaxThrottleDelay,
}})
return cfg, nil
}
12 changes: 11 additions & 1 deletion plugins/indexing/pluginaws/aws_session_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"os"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/client"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
)

Expand Down Expand Up @@ -35,5 +37,13 @@ func NewS3Config() (*aws.Config, error) {
return nil, fmt.Errorf("missing environment variable '%s'", s3EndpointEnvName)
}
// The local emulator requires path style access
return aws.NewConfig().WithEndpoint(endpoint).WithS3ForcePathStyle(true), nil
cfg := aws.NewConfig().WithEndpoint(endpoint).WithS3ForcePathStyle(true)
request.WithRetryer(cfg, CustomRetryer{DefaultRetryer: client.DefaultRetryer{
NumMaxRetries: client.DefaultRetryerMaxNumRetries,
MinRetryDelay: client.DefaultRetryerMinRetryDelay,
MaxRetryDelay: client.DefaultRetryerMaxRetryDelay,
MinThrottleDelay: client.DefaultRetryerMinThrottleDelay,
MaxThrottleDelay: client.DefaultRetryerMaxThrottleDelay,
}})
return cfg, nil
}
30 changes: 30 additions & 0 deletions plugins/indexing/pluginaws/custom_retryer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package pluginaws

import (
"strings"
"time"

"github.com/aws/aws-sdk-go/aws/client"
"github.com/aws/aws-sdk-go/aws/request"
)

type CustomRetryer struct {
client.DefaultRetryer
}

func (r CustomRetryer) MaxRetries() int {
return r.DefaultRetryer.MaxRetries()
}

func (r CustomRetryer) RetryRules(req *request.Request) time.Duration {
return r.DefaultRetryer.RetryRules(req)
}

func (r CustomRetryer) ShouldRetry(req *request.Request) bool {
if strings.Contains(req.Error.Error(), "read: connection reset") {
return true
}

// Fallback to SDK's built in retry rules
return r.DefaultRetryer.ShouldRetry(req)
}
Loading