in src/Microsoft.Azure.SignalR.Management/Resilient/RetryHttpMessageHandler.cs [28:75]
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
IList<Exception>? exceptions = null;
IEnumerator<TimeSpan>? delays = null;
do
{
Exception? ex;
try
{
var response = await base.SendAsync(request, cancellationToken);
if (_canRetry(response.StatusCode))
{
var innerException = new HttpRequestException(
$"Response status code does not indicate success: {(int)response.StatusCode} ({response.ReasonPhrase})");
ex = new AzureSignalRRuntimeException(request.RequestUri?.ToString(), innerException);
response.Dispose();
}
else
{
return response;
}
}
catch (TaskCanceledException operationCanceledException) when (!cancellationToken.IsCancellationRequested && operationCanceledException.InnerException is TimeoutException)
{
// Thrown by our timeout handler
ex = operationCanceledException;
}
delays ??= _retryDelayProvider.GetDelays().GetEnumerator();
if (!delays.MoveNext())
{
if (exceptions == null)
{
throw ex;
}
else
{
exceptions.Add(ex);
throw new AzureSignalRRuntimeException(request.RequestUri?.ToString(), new AggregateException(exceptions));
}
}
else
{
exceptions ??= new List<Exception>();
exceptions.Add(ex);
}
await Task.Delay(delays.Current, cancellationToken);
} while (true);
}