Skip to content

Support backoff retry strategy in Retry.go  #837

@isopropylcyanide

Description

@isopropylcyanide

Currently, tchannel-go/retry.go offers RunWithRetry(runCtx context.Context, f RetriableFunc) which is a straight for loop of the func upto retryOpts.MaxAttempts.

It does not offer a way for callers to specify a backoff strategy.

A backoff strategy (such as backoff.Exponential or backoff.FixedDelay) would be useful to not wreak havoc at an unhealthy backend. The current implementation will shoot 1 + 5 (default retries) calls at the backend.

The proposal is to support a backoff strategy in RetryOptions

// RetryOptions are the retry options used to configure RunWithRetry.
type RetryOptions struct {
	...
	TimeoutPerAttempt time.Duration

        BackoffStrategy BackoffStrategy
}
var defaultRetryOptions = &RetryOptions{
	MaxAttempts: 5,
        BackoffStrategy : nil // or fixed or backoff
}
  • If BackoffStrategy is nil, the existing behaviour continues.
  • If BackoffStrategy is fixed delay, implement a fixed delay between retries
  • If BackoffStrategy is exponential, implement an exponentially decaying delay exponentially between retries.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions