diff --git a/api/common/conf_s3.go b/api/common/conf_s3.go index 2401119f..1e6e238f 100644 --- a/api/common/conf_s3.go +++ b/api/common/conf_s3.go @@ -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" @@ -55,6 +57,7 @@ type S3Config struct { Session *session.Session BucketOwner string + MaxRetries int } var s3Session *session.Session @@ -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 } @@ -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 } diff --git a/internal/backend_s3.go b/internal/backend_s3.go index 3ee2d489..3796a3b2 100644 --- a/internal/backend_s3.go +++ b/internal/backend_s3.go @@ -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 {