diff --git a/README.md b/README.md index 3ab754724..545d2e891 100644 --- a/README.md +++ b/README.md @@ -310,6 +310,8 @@ 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 Most shells can attempt to expand wildcards before passing the arguments to diff --git a/storage/s3.go b/storage/s3.go index 6561a6a70..9eababd35 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.DebugMessage{Err: err.Error()} + log.Debug(msg) + } + + return shouldRetry } var insecureHTTPClient = &http.Client{ diff --git a/storage/s3_test.go b/storage/s3_test.go index f330260b9..3a45cd730 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("debug", false) + testcases := []struct { name string err error