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

storage/s3: propagate retryable errors from sdk to the user #261

Merged
merged 3 commits into from
Jan 6, 2021
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions storage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 2 additions & 0 deletions storage/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ func TestS3ListContextCancelled(t *testing.T) {
}

func TestS3Retry(t *testing.T) {
log.Init("debug", false)

testcases := []struct {
name string
err error
Expand Down