aws-sdk-go-v2: github.com/aws/aws-sdk-go-v2/aws/retry Index | Files

package retry

import "github.com/aws/aws-sdk-go-v2/aws/retry"

Index

Package Files

errors.go jitter_backoff.go middleware.go retry.go retryable_error.go standard.go timeout_error.go

Constants

const (
    // DefaultMaxAttempts is the maximum of attempts for an API request
    DefaultMaxAttempts int = 3

    // DefaultMaxBackoff is the maximum back off delay between attempts
    DefaultMaxBackoff time.Duration = 20 * time.Second
)
const (
    DefaultRetryRateTokens  uint = 500
    DefaultRetryCost        uint = 5
    DefaultRetryTimeoutCost uint = 10
    DefaultNoRetryIncrement uint = 1
)

Default retry token quota values.

Variables

var DefaultRetryableErrorCodes = map[string]struct{}{
    "RequestTimeout":          {},
    "RequestTimeoutException": {},

    "Throttling":                             {},
    "ThrottlingException":                    {},
    "ThrottledException":                     {},
    "RequestThrottledException":              {},
    "TooManyRequestsException":               {},
    "ProvisionedThroughputExceededException": {},
    "TransactionInProgressException":         {},
    "RequestLimitExceeded":                   {},
    "BandwidthLimitExceeded":                 {},
    "LimitExceededException":                 {},
    "RequestThrottled":                       {},
    "SlowDown":                               {},
    "PriorRequestNotComplete":                {},
    "EC2ThrottledException":                  {},
}

DefaultRetryableErrorCodes provides the set of API error codes that should be retried.

var DefaultRetryableHTTPStatusCodes = map[int]struct{}{
    500: {},
    502: {},
    503: {},
    504: {},
}

DefaultRetryableHTTPStatusCodes is the default set of HTTP status codes the SDK should consider as retryable errors.

var DefaultRetryables = []IsErrorRetryable{
    NoRetryCanceledError{},
    RetryableError{},
    RetryableConnectionError{},
    RetryableHTTPStatusCode{
        Codes: DefaultRetryableHTTPStatusCodes,
    },
    RetryableErrorCode{
        Codes: DefaultRetryableErrorCodes,
    },
}

DefaultRetryables provides the set of retryable checks that are used by default.

func AddRetryMiddlewares Uses

func AddRetryMiddlewares(stack *smithymiddle.Stack, options AddRetryMiddlewaresOptions) error

AddRetryMiddlewares adds retry middleware to operation middleware stack

type AddRetryMiddlewaresOptions Uses

type AddRetryMiddlewaresOptions struct {
    Retryer Retryer

    // Enable the logging of retry attempts performed by the SDK.
    // This will include logging retry attempts, unretryable errors, and when max attempts are reached.
    LogRetryAttempts bool
}

AddRetryMiddlewaresOptions is the set of options that can be passed to AddRetryMiddlewares for configuring retry associated middleware.

type Attempt Uses

type Attempt struct {
    // Enable the logging of retry attempts performed by the SDK.
    // This will include logging retry attempts, unretryable errors, and when max attempts are reached.
    LogAttempts bool
    // contains filtered or unexported fields
}

Attempt is a Smithy FinalizeMiddleware that handles retry attempts using the provided Retryer implementation

func NewAttemptMiddleware Uses

func NewAttemptMiddleware(retryer Retryer, requestCloner RequestCloner, optFns ...func(*Attempt)) *Attempt

NewAttemptMiddleware returns a new Attempt

func (Attempt) HandleFinalize Uses

func (r Attempt) HandleFinalize(ctx context.Context, in smithymiddle.FinalizeInput, next smithymiddle.FinalizeHandler) (
    out smithymiddle.FinalizeOutput, metadata smithymiddle.Metadata, err error,
)

HandleFinalize utilizes the provider Retryer implementation to attempt retries over the next handler

func (*Attempt) ID Uses

func (r *Attempt) ID() string

ID returns the middleware identifier

type BackoffDelayer Uses

type BackoffDelayer interface {
    BackoffDelay(attempt int, err error) (time.Duration, error)
}

BackoffDelayer provides the interface for determining the delay to before another request attempt, that previously failed.

type BackoffDelayerFunc Uses

type BackoffDelayerFunc func(int, error) (time.Duration, error)

BackoffDelayerFunc provides a wrapper around a function to determine the backoff delay of an attempt retry.

func (BackoffDelayerFunc) BackoffDelay Uses

func (fn BackoffDelayerFunc) BackoffDelay(attempt int, err error) (time.Duration, error)

BackoffDelay returns the delay before attempt to retry a request.

type ExponentialJitterBackoff Uses

type ExponentialJitterBackoff struct {
    // contains filtered or unexported fields
}

ExponentialJitterBackoff provides backoff delays with jitter based on the number of attempts.

func NewExponentialJitterBackoff Uses

func NewExponentialJitterBackoff(maxBackoff time.Duration) *ExponentialJitterBackoff

NewExponentialJitterBackoff returns an ExponentialJitterBackoff configured for the max backoff.

func (*ExponentialJitterBackoff) BackoffDelay Uses

func (j *ExponentialJitterBackoff) BackoffDelay(attempt int, err error) (time.Duration, error)

BackoffDelay returns the duration to wait before the next attempt should be made. Returns an error if unable get a duration.

type IsErrorRetryable Uses

type IsErrorRetryable interface {
    IsErrorRetryable(error) aws.Ternary
}

IsErrorRetryable provides the interface of an implementation to determine if a error as the result of an operation is retryable.

type IsErrorRetryableFunc Uses

type IsErrorRetryableFunc func(error) aws.Ternary

IsErrorRetryableFunc wraps a function with the IsErrorRetryable interface.

func (IsErrorRetryableFunc) IsErrorRetryable Uses

func (fn IsErrorRetryableFunc) IsErrorRetryable(err error) aws.Ternary

IsErrorRetryable returns if the error is retryable.

type IsErrorRetryables Uses

type IsErrorRetryables []IsErrorRetryable

IsErrorRetryables is a collection of checks to determine of the error is retryable. Iterates through the checks and returns the state of retryable if any check returns something other than unknown.

func (IsErrorRetryables) IsErrorRetryable Uses

func (r IsErrorRetryables) IsErrorRetryable(err error) aws.Ternary

IsErrorRetryable returns if the error is retryable if any of the checks in the list return a value other than unknown.

type IsErrorTimeout Uses

type IsErrorTimeout interface {
    IsErrorTimeout(err error) aws.Ternary
}

IsErrorTimeout provides the interface of an implementation to determine if a error matches.

type IsErrorTimeoutFunc Uses

type IsErrorTimeoutFunc func(error) aws.Ternary

IsErrorTimeoutFunc wraps a function with the IsErrorTimeout interface.

func (IsErrorTimeoutFunc) IsErrorTimeout Uses

func (fn IsErrorTimeoutFunc) IsErrorTimeout(err error) aws.Ternary

IsErrorTimeout returns if the error is retryable.

type IsErrorTimeouts Uses

type IsErrorTimeouts []IsErrorTimeout

IsErrorTimeouts is a collection of checks to determine of the error is retryable. Iterates through the checks and returns the state of retryable if any check returns something other than unknown.

func (IsErrorTimeouts) IsErrorTimeout Uses

func (ts IsErrorTimeouts) IsErrorTimeout(err error) aws.Ternary

IsErrorTimeout returns if the error is retryable if any of the checks in the list return a value other than unknown.

type MaxAttemptsError Uses

type MaxAttemptsError struct {
    Attempt int
    Err     error
}

MaxAttemptsError provides the error when the maximum number of attempts have been exceeded.

func (*MaxAttemptsError) Error Uses

func (e *MaxAttemptsError) Error() string

func (*MaxAttemptsError) Unwrap Uses

func (e *MaxAttemptsError) Unwrap() error

Unwrap returns the nested error causing the max attempts error. Provides the implementation for errors.Is and errors.As to unwrap nested errors.

type MetricsHeader Uses

type MetricsHeader struct{}

MetricsHeader attaches SDK request metric header for retries to the transport

func (MetricsHeader) HandleFinalize Uses

func (r MetricsHeader) HandleFinalize(ctx context.Context, in smithymiddle.FinalizeInput, next smithymiddle.FinalizeHandler) (
    out smithymiddle.FinalizeOutput, metadata smithymiddle.Metadata, err error,
)

HandleFinalize attaches the sdk request metric header to the transport layer

func (*MetricsHeader) ID Uses

func (r *MetricsHeader) ID() string

ID returns the middleware identifier

type NoRetryCanceledError Uses

type NoRetryCanceledError struct{}

NoRetryCanceledError detects if the error was an request canceled error and returns if so.

func (NoRetryCanceledError) IsErrorRetryable Uses

func (NoRetryCanceledError) IsErrorRetryable(err error) aws.Ternary

IsErrorRetryable returns the error is not retryable if the request was canceled.

type RateLimiter Uses

type RateLimiter interface {
    GetToken(ctx context.Context, cost uint) (releaseToken func() error, err error)
    AddTokens(uint) error
}

RateLimiter provides the interface for limiting the rate of request retries allowed by the retrier.

type RequestCloner Uses

type RequestCloner func(interface{}) interface{}

RequestCloner is a function that can take an input request type and clone the request for use in a subsequent retry attempt

type RetryableConnectionError Uses

type RetryableConnectionError struct{}

RetryableConnectionError determines if the underlying error is an HTTP connection and returns if it should be retried.

Includes errors such as connection reset, connection refused, net dial, temporary, and timeout errors.

func (RetryableConnectionError) IsErrorRetryable Uses

func (r RetryableConnectionError) IsErrorRetryable(err error) aws.Ternary

IsErrorRetryable returns if the error is caused by and HTTP connection error, and should be retried.

type RetryableError Uses

type RetryableError struct{}

RetryableError is an IsErrorRetryable implementation which uses the optional interface Retryable on the error value to determine if the error is retryable.

func (RetryableError) IsErrorRetryable Uses

func (RetryableError) IsErrorRetryable(err error) aws.Ternary

IsErrorRetryable returns if the error is retryable if it satisfies the Retryable interface, and returns if the attempt should be retried.

type RetryableErrorCode Uses

type RetryableErrorCode struct {
    Codes map[string]struct{}
}

RetryableErrorCode determines if an attempt should be retried based on the API error code.

func (RetryableErrorCode) IsErrorRetryable Uses

func (r RetryableErrorCode) IsErrorRetryable(err error) aws.Ternary

IsErrorRetryable return if the error is retryable based on the error codes. Returns unknown if the error doesn't have a code or it is unknown.

type RetryableHTTPStatusCode Uses

type RetryableHTTPStatusCode struct {
    Codes map[int]struct{}
}

RetryableHTTPStatusCode provides a IsErrorRetryable based on HTTP status codes.

func (RetryableHTTPStatusCode) IsErrorRetryable Uses

func (r RetryableHTTPStatusCode) IsErrorRetryable(err error) aws.Ternary

IsErrorRetryable return if the passed in error is retryable based on the HTTP status code.

type Retryer Uses

type Retryer interface {
    // IsErrorRetryable returns if the failed request is retryable. This check
    // should determine if the error can be retried, or if the error is
    // terminal.
    IsErrorRetryable(error) bool

    // MaxAttempts returns the maximum number of attempts that can be made for
    // a request before failing. A value of 0 implies that the request should
    // be retried until it succeeds if the errors are retryable.
    MaxAttempts() int

    // RetryDelay returns the delay that should be used before retrying the
    // request. Will return error if the if the delay could not be determined.
    RetryDelay(attempt int, opErr error) (time.Duration, error)

    // GetRetryToken attempts to deduct the retry cost from the retry token pool.
    // Returning the token release function, or error.
    GetRetryToken(ctx context.Context, opErr error) (releaseToken func(error) error, err error)

    // GetInitalToken returns the initial request token that can increment the
    // retry token pool if the request is successful.
    GetInitialToken() (releaseToken func(error) error)
}

Retryer defines an interface for extension utilities to extend the built in retryer.

func AddWithErrorCodes Uses

func AddWithErrorCodes(r Retryer, codes ...string) Retryer

AddWithErrorCodes returns a Retryer with additional error codes considered for determining if the error should be retried.

func AddWithMaxAttempts Uses

func AddWithMaxAttempts(r Retryer, max int) Retryer

AddWithMaxAttempts returns a Retryer with MaxAttempts set to the value specified.

func AddWithMaxBackoffDelay Uses

func AddWithMaxBackoffDelay(r Retryer, delay time.Duration) Retryer

AddWithMaxBackoffDelay returns a retryer wrapping the passed in retryer overriding the RetryDelay behavior for a alternate minimum initial backoff delay.

type Standard Uses

type Standard struct {
    // contains filtered or unexported fields
}

Standard is the standard retry pattern for the SDK. It uses a set of retryable checks to determine of the failed request should be retried, and what retry delay should be used.

func NewStandard Uses

func NewStandard(fnOpts ...func(*StandardOptions)) *Standard

NewStandard initializes a standard retry behavior with defaults that can be overridden via functional options.

func (*Standard) GetInitialToken Uses

func (s *Standard) GetInitialToken() func(error) error

GetInitialToken returns the initial request token that can increment the retry token pool if the request is successful.

func (*Standard) GetRetryToken Uses

func (s *Standard) GetRetryToken(ctx context.Context, err error) (func(error) error, error)

GetRetryToken attempts to deduct the retry cost from the retry token pool. Returning the token release function, or error.

func (*Standard) IsErrorRetryable Uses

func (s *Standard) IsErrorRetryable(err error) bool

IsErrorRetryable returns if the error is can be retried or not. Should not consider the number of attempts made.

func (*Standard) MaxAttempts Uses

func (s *Standard) MaxAttempts() int

MaxAttempts returns the maximum number of attempts that can be made for a request before failing.

func (*Standard) RetryDelay Uses

func (s *Standard) RetryDelay(attempt int, err error) (time.Duration, error)

RetryDelay returns the delay to use before another request attempt is made.

type StandardOptions Uses

type StandardOptions struct {
    MaxAttempts int
    MaxBackoff  time.Duration
    Backoff     BackoffDelayer

    Retryables []IsErrorRetryable
    Timeouts   []IsErrorTimeout

    RateLimiter      RateLimiter
    RetryCost        uint
    RetryTimeoutCost uint
    NoRetryIncrement uint
}

StandardOptions provides the functional options for configuring the standard retryable, and delay behavior.

type TimeouterError Uses

type TimeouterError struct{}

TimeouterError provides the IsErrorTimeout implementation for determining if an error is a timeout based on type with the Timeout method.

func (TimeouterError) IsErrorTimeout Uses

func (t TimeouterError) IsErrorTimeout(err error) aws.Ternary

IsErrorTimeout returns if the error is a timeout error.

Package retry imports 18 packages (graph) and is imported by 456 packages. Updated 2020-11-05. Refresh now. Tools for package owners.