hashicorp / go-retryablehttp

Retryable HTTP client in Go
Mozilla Public License 2.0
1.99k stars 251 forks source link

Custom `CheckRetry` apparently not working? #111

Open andreyvital opened 4 years ago

andreyvital commented 4 years ago

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:

// 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.

ryanuber commented 3 years ago

Hey @andreyvital ! Thanks for opening this, and sorry for our delay.

What you're doing looks fine, but without seeing the actual error I'm unsure if it's safe to assume that either of your type assertions would work. Did you confirm that the errors being returned implemented the Timeout() or Temporary() interfaces you've defined?

If you fixed the issue since you reported it, would you mind confirming if this was a go-retryablehttp problem or something else? Thanks!