From 92b4d4053cf0c191b65f2c1c07a9fd3ccef35bac Mon Sep 17 00:00:00 2001 From: Onur Sonmez Date: Fri, 18 Dec 2020 22:16:20 +0300 Subject: [PATCH 1/3] aws/s3: propagate retryable errors from sdk to the user --- storage/s3.go | 13 ++++++++++--- storage/s3_test.go | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/storage/s3.go b/storage/s3.go index 6561a6a70..b53f9f98e 100644 --- a/storage/s3.go +++ b/storage/s3.go @@ -737,11 +737,18 @@ func newCustomRetryer(maxRetries int) *customRetryer { // ShouldRetry overrides SDK's built in DefaultRetryer, adding custom retry // logics that are not included in the SDK. func (c *customRetryer) ShouldRetry(req *request.Request) bool { - if errHasCode(req.Error, "InternalError") || errHasCode(req.Error, "RequestTimeTooSkewed") { - return true + shouldRetry := errHasCode(req.Error, "InternalError") || errHasCode(req.Error, "RequestTimeTooSkewed") + if !shouldRetry { + shouldRetry = c.DefaultRetryer.ShouldRetry(req) } - return c.DefaultRetryer.ShouldRetry(req) + if shouldRetry && req.Error != nil { + err := fmt.Errorf("retryable error: %v", req.Error) + msg := log.ErrorMessage{Err: err.Error()} + log.Error(msg) + } + + return shouldRetry } var insecureHTTPClient = &http.Client{ diff --git a/storage/s3_test.go b/storage/s3_test.go index f330260b9..1f66e458b 100644 --- a/storage/s3_test.go +++ b/storage/s3_test.go @@ -286,6 +286,8 @@ func TestS3ListContextCancelled(t *testing.T) { } func TestS3Retry(t *testing.T) { + log.Init("error", false) + testcases := []struct { name string err error From ef3b23cb29d96548645a6707f839fdea88e2d2d4 Mon Sep 17 00:00:00 2001 From: Onur Sonmez Date: Tue, 5 Jan 2021 09:23:09 +0300 Subject: [PATCH 2/3] Use debug level logging --- README.md | 1 + storage/s3.go | 4 ++-- storage/s3_test.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3ab754724..7dcc55b4c 100644 --- a/README.md +++ b/README.md @@ -309,6 +309,7 @@ server-side throttling errors. Non-retriable errors, such as `invalid credentials`, `authorization errors` etc, will not be retried. By default, `s5cmd` will retry 10 times for up to a minute. Number of retries are adjustable via `--retry-count` flag. +ℹ️ Enable debug level logging for displaying retryable errors. ## Using wildcards diff --git a/storage/s3.go b/storage/s3.go index b53f9f98e..9eababd35 100644 --- a/storage/s3.go +++ b/storage/s3.go @@ -744,8 +744,8 @@ func (c *customRetryer) ShouldRetry(req *request.Request) bool { if shouldRetry && req.Error != nil { err := fmt.Errorf("retryable error: %v", req.Error) - msg := log.ErrorMessage{Err: err.Error()} - log.Error(msg) + msg := log.DebugMessage{Err: err.Error()} + log.Debug(msg) } return shouldRetry diff --git a/storage/s3_test.go b/storage/s3_test.go index 1f66e458b..3a45cd730 100644 --- a/storage/s3_test.go +++ b/storage/s3_test.go @@ -286,7 +286,7 @@ func TestS3ListContextCancelled(t *testing.T) { } func TestS3Retry(t *testing.T) { - log.Init("error", false) + log.Init("debug", false) testcases := []struct { name string From f2f5a0ab30cf81c49e5f7c33dc541e220191b665 Mon Sep 17 00:00:00 2001 From: Onur Sonmez Date: Tue, 5 Jan 2021 09:24:47 +0300 Subject: [PATCH 3/3] Update README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7dcc55b4c..545d2e891 100644 --- a/README.md +++ b/README.md @@ -309,6 +309,7 @@ server-side throttling errors. Non-retriable errors, such as `invalid credentials`, `authorization errors` etc, will not be retried. By default, `s5cmd` will retry 10 times for up to a minute. Number of retries are adjustable via `--retry-count` flag. + ℹ️ Enable debug level logging for displaying retryable errors. ## Using wildcards