Class MassiveRetryHandler
- Namespace
- MassiveDotNet.Http
- Assembly
- MassiveDotNet.dll
Retries a failed request a bounded number of times, with exponential backoff and jitter.
public sealed class MassiveRetryHandler : DelegatingHandler, IDisposable
- Inheritance
-
MassiveRetryHandler
- Implements
- Inherited Members
Remarks
Retried: HTTP 429 and 5xx, and a transport failure that describes the connection rather than an answer, meaning an HttpRequestException whose HttpRequestError is Unknown, NameResolutionError, ConnectionError, SecureConnectionError, HttpProtocolError or ResponseEnded. Unknown is on that list because the runtime reports a connection reset mid-send under it. Every other 4xx, and every other transport failure, describes a request, an answer or a configuration that will fail identically however often it is sent.
Only a failure before the response headers arrive can be retried here. The transport reads with ResponseHeadersRead, so this handler hands a response on once its headers are in, and a connection that breaks while the body is read surfaces from deserialization, outside it.
A timeout is never retried here. Timeout cancels the token this handler runs under, so it bounds every attempt and every backoff of one call together, and once it fires nothing inside the handler can send again. A caller who wants a timed-out request retried makes a fresh call, which gets a fresh timeout.
This handler must sit inside MassiveAuthenticationHandler. Under
QueryString the authentication handler rewrites the
request URI, so a retry placed outside it re-authenticates each attempt and appends the key
again — producing ?apiKey=k&apiKey=k&apiKey=k. The request still succeeds, so
the only symptom is the key reaching access logs once per attempt, which is what constitution
rule 11 exists to prevent. CreateHandlerPipeline(MassiveClientOptions, HttpMessageHandler) composes
the order correctly; assemble it by hand only with that ordering in mind (D30).
Constructors
MassiveRetryHandler(MassiveRetryOptions)
Initializes a new instance of the MassiveRetryHandler class.
public MassiveRetryHandler(MassiveRetryOptions options)
Parameters
optionsMassiveRetryOptionsThe retry policy to apply.
Exceptions
- ArgumentNullException
optionsis null.- InvalidOperationException
optionsholds a value it cannot act on.
Methods
Send(HttpRequestMessage, CancellationToken)
Sends an HTTP request to the inner handler to send to the server.
protected override HttpResponseMessage Send(HttpRequestMessage request, CancellationToken cancellationToken)
Parameters
requestHttpRequestMessageThe HTTP request message to send to the server.
cancellationTokenCancellationTokenA cancellation token to cancel operation.
Returns
- HttpResponseMessage
An HTTP response message.
Exceptions
- OperationCanceledException
The cancellation token was canceled. This exception is stored into the returned task.
- NotSupportedException
Always. The SDK issues no synchronous requests.
SendAsync(HttpRequestMessage, CancellationToken)
Sends an HTTP request to the inner handler to send to the server as an asynchronous operation.
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
Parameters
requestHttpRequestMessageThe HTTP request message to send to the server.
cancellationTokenCancellationTokenA cancellation token to cancel operation.
Returns
- Task<HttpResponseMessage>
The task object representing the asynchronous operation.
Exceptions
- ArgumentNullException
The
requestwas null.- OperationCanceledException
The cancellation token was canceled. This exception is stored into the returned task.