hashicorp / hashicorp/go-retryablehttp

Custom `CheckRetry` apparently not working?

Open
#111 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
2.3k
Forks
298
PR merge metrics
No merged PRs in 30d

Description

So.....based off this: https://github.com/hashicorp/go-retryablehttp/blob/master/client.go#L399-L405. By default, it ignores timeout errors. But I do want to force retry on those, here's what I did:

```Go
// Temporaryable is to match an error that has `.Temporary()`
type Temporaryable interface {
Temporary() bool
}

// Timeoutable is to match an error that has `.Timeout()`
type Timeoutable interface {
Timeout() bool
}

retryClient.CheckRetry = func(ctx context.Context, resp *http.Response, err error) (bool, error) {
if terr, ok := err.(Temporaryable); ok && terr.Temporary() {
return true, nil
}

if terr, ok := err.(Timeoutable); ok && terr.Timeout() {
return true, nil
}

return retryablehttp.DefaultRetryPolicy(ctx, resp, err)
}
```

However, it doesn't seem to be working—with `RetryMax` set to 10, I can't see it getting past the 1st attempt.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.