Class RetryPolicy
A retry policy specifies all aspects of retry behavior. This includes conditions when the request should be retried, checks of retry limit, preparing the request before retry and introducing delay (backoff) before retries.
public abstract class RetryPolicy
- Inheritance
-
RetryPolicy
- Derived
- Inherited Members
Constructors
RetryPolicy()
protected RetryPolicy()
Properties
ErrorCodesToRetryOn
List of AWS specific error codes which are returned as part of the error response. These error codes will be retried.
public ICollection<string> ErrorCodesToRetryOn { get; protected set; }
Property Value
HttpStatusCodesToRetryOn
The standard set of transient error, HTTP status codes to retry on. 502 and 504 are returned by proxies. These can also be returned for S3 accelerate requests which are served by CloudFront.
public ICollection<HttpStatusCode> HttpStatusCodesToRetryOn { get; protected set; }
Property Value
Logger
The logger used to log messages.
public ILogger Logger { get; set; }
Property Value
MaxRetries
Maximum number of retries to be performed. This does not count the initial request.
public int MaxRetries { get; protected set; }
Property Value
RetryCapacity
This parameter serves as the value to the CapacityManager.Container datastructure. Its properties include the available capacity left for making a retry request and the maximum capacity size.
protected RetryCapacity RetryCapacity { get; set; }
Property Value
ThrottlingErrorCodes
The standard set of throttling error codes
public virtual ICollection<string> ThrottlingErrorCodes { get; protected set; }
Property Value
TimeoutErrorCodesToRetryOn
The standard set of timeout error codes to retry on.
public ICollection<string> TimeoutErrorCodesToRetryOn { get; protected set; }
Property Value
WebExceptionStatusesToRetryOn
Set of web exception status codes to retry on.
public ICollection<WebExceptionStatus> WebExceptionStatusesToRetryOn { get; protected set; }
Property Value
Methods
CanRetry(IExecutionContext)
Returns true if the request is in a state where it can be retried, else false.
public abstract bool CanRetry(IExecutionContext executionContext)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.
Returns
- bool
Returns true if the request is in a state where it can be retried, else false.
ContainErrorMessage(Exception, HashSet<string>)
protected static bool ContainErrorMessage(Exception exception, HashSet<string> errorMessages)
Parameters
Returns
GetRetryCapacityKey(IClientConfig)
Creates a key for storing retry capacity data. Key is based on service's url (we store retry capacity per service's url variant). If ClientConfig's ServiceURL override is set we use it as a key, otherwise we construct key based on ClientConfig's schema, region, service, fips, dualstack parameters. This value is unique key per real service's url variant.
protected static string GetRetryCapacityKey(IClientConfig config)
Parameters
config
IClientConfig
Returns
IsServiceTimeoutError(Exception)
Determines if the exception is a known timeout error code that should be retried under the timeout error category.
public virtual bool IsServiceTimeoutError(Exception exception)
Parameters
exception
ExceptionThe current exception to check.
Returns
- bool
true if the exception is considered a timeout else false
IsThrottlingError(Exception)
Determines if an AmazonServiceException is a throttling error
public virtual bool IsThrottlingError(Exception exception)
Parameters
exception
ExceptionThe current exception to check.
Returns
- bool
true if it is a throttling error else false.
IsTransientError(IExecutionContext, Exception)
Determines if an AmazonServiceException is a transient error that should be retried.
public virtual bool IsTransientError(IExecutionContext executionContext, Exception exception)
Parameters
executionContext
IExecutionContextThe current execution context
exception
ExceptionThe current exception to check.
Returns
- bool
true if the exception is a transient error else false.
IsTransientSslError(Exception)
public static bool IsTransientSslError(Exception exception)
Parameters
exception
Exception
Returns
NotifySuccess(IExecutionContext)
Virtual method that gets called on a successful request response.
public virtual void NotifySuccess(IExecutionContext executionContext)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.
ObtainSendToken(IExecutionContext, Exception)
This method uses a token bucket to enforce the maximum sending rate.
public virtual void ObtainSendToken(IExecutionContext executionContext, Exception exception)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.
exception
ExceptionIf the prior request failed, this exception is expected to be the exception that occurred during the prior request failure.
ObtainSendTokenAsync(IExecutionContext, Exception)
This method uses a token bucket to enforce the maximum sending rate.
public virtual Task ObtainSendTokenAsync(IExecutionContext executionContext, Exception exception)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.
exception
ExceptionIf the prior request failed, this exception is expected to be the exception that occurred during the prior request failure.
Returns
OnRetry(IExecutionContext)
Virtual method that gets called before a retry request is initiated. The value returned is True by default(retry throttling feature is disabled).
public virtual bool OnRetry(IExecutionContext executionContext)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.
Returns
OnRetry(IExecutionContext, bool)
Virtual method that gets called before a retry request is initiated. The value returned is True by default(retry throttling feature is disabled).
public virtual bool OnRetry(IExecutionContext executionContext, bool bypassAcquireCapacity)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.
bypassAcquireCapacity
booltrue to bypass any attempt to acquire capacity on a retry
Returns
OnRetry(IExecutionContext, bool, bool)
Virtual method that gets called before a retry request is initiated. The value returned is True by default(retry throttling feature is disabled).
public virtual bool OnRetry(IExecutionContext executionContext, bool bypassAcquireCapacity, bool isThrottlingError)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.
bypassAcquireCapacity
booltrue to bypass any attempt to acquire capacity on a retry
isThrottlingError
booltrue if the error that will be retried is a throttling error
Returns
Retry(IExecutionContext, Exception)
Checks if a retry should be performed with the given execution context and exception.
public bool Retry(IExecutionContext executionContext, Exception exception)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.
exception
ExceptionThe exception thrown after issuing the request.
Returns
- bool
Returns true if the request should be retried, else false. The exception is retried if it matches with clockskew error codes.
RetryAsync(IExecutionContext, Exception)
Checks if a retry should be performed with the given execution context and exception.
public Task<bool> RetryAsync(IExecutionContext executionContext, Exception exception)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.
exception
ExceptionThe exception throw after issuing the request.
Returns
- Task<bool>
Returns true if the request should be retried, else false. The exception is retried if it matches with clockskew error codes.
RetryForException(IExecutionContext, Exception)
Return true if the request should be retried for the given exception.
public abstract bool RetryForException(IExecutionContext executionContext, Exception exception)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.
exception
ExceptionThe exception thrown by the previous request.
Returns
- bool
Return true if the request should be retried.
RetryForExceptionAsync(IExecutionContext, Exception)
Return true if the request should be retried for the given exception.
public abstract Task<bool> RetryForExceptionAsync(IExecutionContext executionContext, Exception exception)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.
exception
ExceptionThe exception thrown by the previous request.
Returns
RetryLimitReached(IExecutionContext)
Checks if the retry limit is reached.
public abstract bool RetryLimitReached(IExecutionContext executionContext)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.
Returns
- bool
Return false if the request can be retried, based on number of retries.
WaitBeforeRetry(IExecutionContext)
Waits before retrying a request.
public abstract void WaitBeforeRetry(IExecutionContext executionContext)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.
WaitBeforeRetryAsync(IExecutionContext)
Waits before retrying a request.
public abstract Task WaitBeforeRetryAsync(IExecutionContext executionContext)
Parameters
executionContext
IExecutionContextThe execution context which contains both the requests and response context.