-
Notifications
You must be signed in to change notification settings - Fork 533
[Internal] ThinProxy Integration: Adds New HttpTimeoutPolicy and Fix Cross Regional Retry Logic
#5276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kirankumarkolli
merged 9 commits into
master
from
users/kundadebdatta/5275_add_httptimeoutpolicy_for_thin_client
Jul 15, 2025
Merged
[Internal] ThinProxy Integration: Adds New HttpTimeoutPolicy and Fix Cross Regional Retry Logic
#5276
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6504c1c
Code changes to add new timeout policy for thin client.
kundadebdatta 8d404fc
Code changes to add more tests
kundadebdatta 6c6ccc9
Merge branch 'master' into users/kundadebdatta/5275_add_httptimeoutpo…
kundadebdatta 2f3f718
Code changes to fix some nit-pick comments.
kundadebdatta 0f367b3
Code changes to update thin client 3rd timeout value in http timeout …
kundadebdatta 7a8960f
Code changes to add more tests to validate endpoint unavailable scena…
kundadebdatta 4dedb7f
Minor code cleanup
kundadebdatta cf403c4
Remove unnecessary statement
kundadebdatta 7cbd4e8
Merge branch 'master' into users/kundadebdatta/5275_add_httptimeoutpo…
kundadebdatta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
Microsoft.Azure.Cosmos/src/HttpClient/HttpTimeoutPolicyForThinClient.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| //------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| //------------------------------------------------------------ | ||
| namespace Microsoft.Azure.Cosmos | ||
| { | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Net.Http; | ||
|
|
||
| internal sealed class HttpTimeoutPolicyForThinClient : HttpTimeoutPolicy | ||
| { | ||
| public bool shouldRetry; | ||
| public bool shouldThrow503OnTimeout; | ||
| private static readonly string Name = nameof(HttpTimeoutPolicyForThinClient); | ||
| public static readonly HttpTimeoutPolicy InstanceShouldRetryAndThrow503OnTimeout = new HttpTimeoutPolicyForThinClient(true, true); | ||
| public static readonly HttpTimeoutPolicy InstanceShouldNotRetryAndThrow503OnTimeout = new HttpTimeoutPolicyForThinClient(true, false); | ||
|
|
||
| private HttpTimeoutPolicyForThinClient( | ||
| bool shouldThrow503OnTimeout, | ||
| bool shouldRetry) | ||
| { | ||
| this.shouldThrow503OnTimeout = shouldThrow503OnTimeout; | ||
| this.shouldRetry = shouldRetry; | ||
| } | ||
|
|
||
| private readonly IReadOnlyList<(TimeSpan requestTimeout, TimeSpan delayForNextRequest)> TimeoutsAndDelays = new List<(TimeSpan requestTimeout, TimeSpan delayForNextRequest)>() | ||
| { | ||
| (TimeSpan.FromSeconds(.5), TimeSpan.Zero), | ||
| (TimeSpan.FromSeconds(1), TimeSpan.Zero), | ||
| (TimeSpan.FromSeconds(5), TimeSpan.Zero), | ||
|
kundadebdatta marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| public override string TimeoutPolicyName => HttpTimeoutPolicyForThinClient.Name; | ||
|
|
||
| public override int TotalRetryCount => this.TimeoutsAndDelays.Count; | ||
|
|
||
| public override IEnumerator<(TimeSpan requestTimeout, TimeSpan delayForNextRequest)> GetTimeoutEnumerator() | ||
| { | ||
| return this.TimeoutsAndDelays.GetEnumerator(); | ||
| } | ||
|
|
||
| public override bool IsSafeToRetry(HttpMethod httpMethod) | ||
| { | ||
| return this.shouldRetry; | ||
| } | ||
|
|
||
| public override bool ShouldRetryBasedOnResponse(HttpMethod requestHttpMethod, HttpResponseMessage responseMessage) | ||
| { | ||
| if (responseMessage == null) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (responseMessage.StatusCode != System.Net.HttpStatusCode.RequestTimeout) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| if (!this.IsSafeToRetry(requestHttpMethod)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| public override bool ShouldThrow503OnTimeout => this.shouldThrow503OnTimeout; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.