Retries and timeouts
What the SDK retries
Section titled “What the SDK retries”The SDK sends the request again after these failures:
- A
408or429response. - A
5xxresponse. - A network failure.
By default, the SDK makes 2 retries. Set MaxRetries to change the number. Set 0 to stop retries.
Each attempt sends the idempotency key of the request. Verifiabl does not charge again for a verification that is complete.
Between attempts, the SDK waits for a longer time after each attempt. If the response has a Retry-After header, the SDK waits for that time.
If the API returns 401, the SDK gets a new access token. Then it sends the request again one time. This retry is not included in MaxRetries.
The SDK does not retry a failed token request. It throws VerifierAuthException. Use IsRetryable to find if the same call can succeed later.
The SDK does not retry NOT_VERIFIED. The same payload gives the same result.
Set the timeout
Section titled “Set the timeout”Timeout is the maximum time for one call to VerifyAsync. The default is 30 seconds. It includes the token request, all retries and the waits between them.
If the next wait does not end before the timeout, the SDK does not retry. It throws the last failure. RetryAfter on the exception gives the wait that the API asked for.
If the timeout ends during a request, the SDK throws VerifierTimeoutException. The verification can be complete.
To stop a call yourself, cancel the CancellationToken that you give to VerifyAsync. The SDK then throws OperationCanceledException. If Verifiabl received the request before you cancel, the verification can be complete. If you send it again, send the same request.
If the retries do not succeed
Section titled “If the retries do not succeed”The SDK throws a VerifierException with IsRetryable set to true. Send the same VerificationRequest again later, in 1 hour or less. A new request is a new verification. Refer to Handle errors.
IsRetryable means that the same call can succeed later. It does not tell you if the last attempt completed.
Your own retries
Section titled “Your own retries”Use the SDK retries, unless your application must schedule the attempts. For your own retries, set MaxRetries to 0. The SDK still gets a new access token one time after a 401.
This helper makes one more call at a maximum. It sends the same request, so the retry sends the same idempotency key. One time limit applies to the two calls and the wait. If the API asks for a wait of more than 1 minute, the helper throws the failure.
static async Task<VerificationResult> VerifyWithOneRetryAsync( IVerifierClient verifier, VerificationRequest request, CancellationToken cancellationToken){ using var deadline = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); deadline.CancelAfter(TimeSpan.FromMinutes(2));
try { return await verifier.VerifyAsync(request, deadline.Token); } catch (VerifierException failure) when (failure.IsRetryable) { TimeSpan delay = failure.RetryAfter ?? TimeSpan.FromSeconds(2); // Give a long wait to the caller to schedule. if (delay > TimeSpan.FromMinutes(1)) { throw; }
await Task.Delay(delay, deadline.Token); return await verifier.VerifyAsync(request, deadline.Token); }}The helper does not retry a second failure. Its time limit gives OperationCanceledException. Map the result after the helper returns. Refer to Map the result.
To send a verification again from a new request, for example from a queue, save the idempotency key before the first attempt. Refer to Idempotency key.