Skip to content

Commit fe72a70

Browse files
committed
Update the safe retry to use address resource type as well.
1 parent b871967 commit fe72a70

3 files changed

Lines changed: 23 additions & 7 deletions

File tree

Microsoft.Azure.Cosmos/src/HttpClient/CosmosHttpClientCore.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ private async Task<HttpResponseMessage> SendHttpHelperAsync(
415415

416416
// Convert OperationCanceledException to 408 when the HTTP client throws it. This makes it clear that the
417417
// the request timed out and was not user canceled operation.
418-
if (isOutOfRetries || !documentServiceRequest.IsReadOnlyRequest)
418+
if (isOutOfRetries || !IsSafeToRetry(documentServiceRequest))
419419
{
420420
// throw current exception (caught in transport handler)
421421
string message =
@@ -440,14 +440,14 @@ private async Task<HttpResponseMessage> SendHttpHelperAsync(
440440

441441
break;
442442
case WebException webException:
443-
if (isOutOfRetries || (!documentServiceRequest.IsReadOnlyRequest && !WebExceptionUtility.IsWebExceptionRetriable(webException)))
443+
if (isOutOfRetries || (!IsSafeToRetry(documentServiceRequest) && !WebExceptionUtility.IsWebExceptionRetriable(webException)))
444444
{
445445
throw;
446446
}
447447

448448
break;
449449
case HttpRequestException httpRequestException:
450-
if (isOutOfRetries || !documentServiceRequest.IsReadOnlyRequest)
450+
if (isOutOfRetries || !IsSafeToRetry(documentServiceRequest))
451451
{
452452
throw;
453453
}
@@ -498,6 +498,15 @@ private static bool IsOutOfRetries(
498498
return !timeoutEnumerator.MoveNext(); // No more retries are configured
499499
}
500500

501+
private static bool IsSafeToRetry(DocumentServiceRequest documentServiceRequest)
502+
{
503+
if (documentServiceRequest == null)
504+
{
505+
return false;
506+
}
507+
return documentServiceRequest.IsReadOnlyRequest || documentServiceRequest.ResourceType == ResourceType.Address;
508+
}
509+
501510
private async Task<HttpResponseMessage> ExecuteHttpHelperAsync(
502511
HttpRequestMessage requestMessage,
503512
ResourceType resourceType,

Microsoft.Azure.Cosmos/src/HttpClient/HttpTimeoutPolicyForPartitionFailover.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ private HttpTimeoutPolicyForPartitionFailover(bool shouldThrow503OnTimeout)
2121

2222
private readonly IReadOnlyList<(TimeSpan requestTimeout, TimeSpan delayForNextRequest)> TimeoutsAndDelays = new List<(TimeSpan requestTimeout, TimeSpan delayForNextRequest)>()
2323
{
24+
(TimeSpan.FromSeconds(.5), TimeSpan.Zero),
2425
(TimeSpan.FromSeconds(.5), TimeSpan.Zero),
2526
(TimeSpan.FromSeconds(1), TimeSpan.Zero),
26-
(TimeSpan.FromSeconds(5), TimeSpan.Zero),
2727
};
2828

2929
public override string TimeoutPolicyName => HttpTimeoutPolicyForPartitionFailover.Name;

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/GatewayStoreModelTest.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -889,15 +889,22 @@ public async Task GatewayStatsDurationTest()
889889
DocumentClientEventSource.Instance);
890890

891891
using (ITrace trace = Tracing.Trace.GetRootTrace(nameof(GatewayStatsDurationTest)))
892-
{
893-
892+
{
893+
894894
Tracing.TraceData.ClientSideRequestStatisticsTraceDatum clientSideRequestStatistics = new Tracing.TraceData.ClientSideRequestStatisticsTraceDatum(DateTime.UtcNow, trace);
895895

896896
await cosmosHttpClient.SendHttpAsync(() => new ValueTask<HttpRequestMessage>(new HttpRequestMessage(HttpMethod.Get, "http://someuri.com")),
897897
ResourceType.Document,
898898
HttpTimeoutPolicyDefault.InstanceShouldThrow503OnTimeout,
899899
clientSideRequestStatistics,
900-
CancellationToken.None);
900+
CancellationToken.None,
901+
documentServiceRequest: new DocumentServiceRequest(
902+
OperationType.Read,
903+
ResourceType.Document,
904+
$"dbs/dummy_db_id/colls/dummy_ct_id",
905+
body: null,
906+
AuthorizationTokenType.PrimaryMasterKey,
907+
headers: null));
901908

902909
Assert.AreEqual(clientSideRequestStatistics.HttpResponseStatisticsList.Count, 2);
903910
// The duration is calculated using date times which can cause the duration to be slightly off. This allows for up to 15 Ms of variance.

0 commit comments

Comments
 (0)