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

Allow to configure a value of maximum retry attempts #629

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 12 additions & 0 deletions api/common/conf_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"encoding/base64"
"fmt"
"net/http"
"os"
"strconv"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/client"
Expand Down Expand Up @@ -55,6 +57,7 @@ type S3Config struct {
Session *session.Session

BucketOwner string
MaxRetries int
}

var s3Session *session.Session
Expand All @@ -66,6 +69,13 @@ func (c *S3Config) Init() *S3Config {
if c.StorageClass == "" {
c.StorageClass = "STANDARD"
}

c.MaxRetries = 4 // Default AWS value
if valueStr, ok := os.LookupEnv("AWS_MAX_ATTEMPTS"); ok {
if valueInt, err := strconv.Atoi(valueStr); err == nil {
c.MaxRetries = valueInt
}
}
return c
}

Expand Down Expand Up @@ -131,6 +141,8 @@ func (c *S3Config) ToAwsConfig(flags *FlagStorage) (*aws.Config, error) {
c.SseCDigest = base64.StdEncoding.EncodeToString(m[:])
}

awsConfig.MaxRetries = &c.MaxRetries

return awsConfig, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/backend_s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (s *S3Backend) detectBucketLocationByHEAD() (err error, isAws bool) {
return
}

allowFails := 3
allowFails := s.config.MaxRetries
for i := 0; i < allowFails; i++ {
resp, err = http.DefaultTransport.RoundTrip(req)
if err != nil {
Expand Down