Skip to content

Commit

Permalink
ClientRetryPolicy: Fixes failover handling of 503 HTTP errors (#3479)
Browse files Browse the repository at this point in the history
* Added Expected Behavior and Tests

* Suggested changes + ported over tests from v2

Co-authored-by: Nalu Tripician <ntripician@microsoft.com>
  • Loading branch information
NaluTripician and NaluTripician committed Sep 30, 2022
1 parent 01d56ab commit dfe1fac
Show file tree
Hide file tree
Showing 2 changed files with 599 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Microsoft.Azure.Cosmos/src/ClientRetryPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private async Task<ShouldRetryResult> ShouldRetryInternalAsync(

// Received 503.0 due to client connect timeout or Gateway
if (statusCode == HttpStatusCode.ServiceUnavailable
&& subStatusCode == SubStatusCodes.Unknown)
&& ClientRetryPolicy.IsRetriableServiceUnavailable(subStatusCode))
{
DefaultTrace.TraceWarning("ClientRetryPolicy: ServiceUnavailable. Refresh cache and retry. Failed Location: {0}; ResourceAddress: {1}",
this.documentServiceRequest?.RequestContext?.LocationEndpointToRoute?.ToString() ?? string.Empty,
Expand All @@ -233,6 +233,12 @@ private async Task<ShouldRetryResult> ShouldRetryInternalAsync(
return null;
}

private static bool IsRetriableServiceUnavailable(SubStatusCodes? subStatusCode)
{
return subStatusCode == SubStatusCodes.Unknown ||
(subStatusCode.HasValue && subStatusCode.Value.IsSDKGeneratedSubStatus());
}

private async Task<ShouldRetryResult> ShouldRetryOnEndpointFailureAsync(
bool isReadRequest,
bool markBothReadAndWriteAsUnavailable,
Expand Down
Loading

0 comments on commit dfe1fac

Please sign in to comment.