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

Retriable errors and backoffs #898

Open
jsha opened this issue Apr 4, 2022 · 1 comment
Open

Retriable errors and backoffs #898

jsha opened this issue Apr 4, 2022 · 1 comment

Comments

@jsha
Copy link
Contributor

jsha commented Apr 4, 2022

I'm working on a tool that uses fetcher.go, and also calls GetProofByHash. I'd like to configure it to do backoffs and retries. I see that fetcher.go uses a Backoff struct provided internally:

bo := &backoff.Backoff{
Min: 1 * time.Second,
Max: 30 * time.Second,
Factor: 2,
Jitter: true,
}
var resp *ct.GetEntriesResponse
// TODO(pavelkalinnikov): Report errors in a LogClient decorator on failure.
if err := bo.Retry(ctx, func() error {
var err error
resp, err = f.client.GetRawEntries(ctx, r.start, r.end)
return err
}); err != nil {
glog.Errorf("%s: GetRawEntries() failed: %v", f.uri, err)
// There is no error reporting yet for this worker, so just retry again.
continue
}
fn(EntryBatch{Start: r.start, Entries: resp.Entries})
r.start += int64(len(resp.Entries))

But I think that usage might be broken. Backoff will only retry on grpc error codes that are retriable, plus the RetriableError struct. The GetRawEntries call I linked to is implemented by jsonclient.GetAndParse, which returns RspErrors. Those RspErrors don't match any of the conditions for retries.

I'd like to propose this: In addition to / instead of backoff.RetriableError, the backoff package should check for some interface, e.g. Retryable() bool. Then jsonclient.RspError can implement Retryable() as: a RspError is retryable if its wrapped error is a net.Timeout error OR the HTTP status code is >500.

What do you think?

@pav-kv
Copy link
Contributor

pav-kv commented May 11, 2022

Good catch, I think you are right. The retry will still happen because of the continue in line 289, but there will be no backoff in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants