-
Notifications
You must be signed in to change notification settings - Fork 491
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
Ensure DNS changes are detected by client #3658
Comments
Our SDK is a We use azure-cosmos-dotnet-v3/Microsoft.Azure.Cosmos/src/HttpClient/CosmosHttpClientCore.cs Lines 102 to 104 in 4e923da
azure-cosmos-dotnet-v3/Microsoft.Azure.Cosmos/src/HttpClient/CosmosHttpClientCore.cs Lines 91 to 92 in 4e923da
In When looking at the Azure SDK PR, they are multi-targetting
However, because we expose a hook to
If they use Dependency Injection, or if they don't:
Reference: https://devblogs.microsoft.com/cosmosdb/httpclientfactory-cosmos-db-net-sdk/#sharing-httpclients The goal of this code is that you create a Unless we multi-target this library to |
Agreed on multi-targeting. One hypothesis is that custom handler is only used in rare cases => default multi-targeting will benefit majority of CX. |
If we multi-target, we can definitively do it internally. Yes, my assumption would be that customers rarely customize the HttpClientFactory |
Few options (from offline conversation)
|
reflection to try to do it we happen to be running on .NET6 - Kevin P. |
Potential solutions
Solution 1
Solution 2
Solution 3
|
Findings on .NET Detection of DNS ChangesHere are my findings on the current behavior of .NET 6.0 and 4.8 in regard to how DNS changes are detected. For all the following test, first an instance of a
While in the loop, changes are made to the .NET 6.0 - Default BehaviorIn .NET 6.0, changes to the IP address are only detected if a new Http Connection is made. The connection will be dropped after a timeout period if the connection is a This is the expected behavior based on the customer reported issues. .NET 4.8 - Default Behavior
.NET 4.8 behaves the same as .NET 6.0. Using Reflection to create an Instance of
|
Why is it opening a new connection for the second request, but not any subsequent requests? |
@karelz - Wondering if you can help us out with some DNS related queries. Part of Azure Cosmos DB's strategy for moving to different regions involves updating DNS, but we recently observed some cases where our clients didn't pick up the changes, and we're trying to make the SDK work better in these sort of cases. It's complicated by the fact that we're a .NET Standard 2.0 library, and still have plenty of use on .NET Framework. |
Good question, @NaluTripician can you confirm this? With the default HttpClient, iIf the Timeout is 65 seconds and requests are happening faster, if you change the hosts file, is it picking up the changes or is it not? My understanding was that it was not, but the sentence seems to imply the contrary? |
I think I might know what’s going on here, there is a 10 second delay I added before the loop in the test to give me time to start the |
After some more testing I do not think that this is the issue. I am still seeing the connection drop after the first send, even when setting the |
Another possible reason that the HTTP connections were being dropped in the test was that the target IP address used had no keepalive, |
Updated original comment with results from fix to tests. |
@Pilchie sure, we can try. However note that DNS is done by OS on both .NET Framework and .NET Core. We as .NET do not interact with it, we just use it and leave all policy decisions and other fun stuff to OS. BTW: We toyed with the idea to implement our own DNS - see dotnet/runtime#19443. It has upsides (TTL available, etc.) and also downsides (no cross-process sharing which OS does). As a result, we didn't see huge need given that it would be only an alternative without clear winner between the 2 implementations. |
Understood - this issue is really about connection lifetimes. As long as a new connection is established, the OS seems to do the right thing, but connection pooling means that we sometimes re-use a connection to an old host. That's what we're trying to address. |
Background: https://azure.status.microsoft/en-us/status/history/ Tracking ID: VN11-JD8
Reference: https://www.meziantou.net/avoid-dns-issues-with-httpclient-in-dotnet.htm
Azure SDK reference: Azure/azure-sdk-for-net#19457
Azure SDK has followed this article and added the default configuration to HttpClient on Azure/azure-sdk-for-net#19524
More code pointers:
We should evaluate if we want to follow this approach, the Azure SDK went through these changes so we can assume they are ok, but it's worth investigating.
There is the alternative that none of these APIs are available for NETStandard 2.0
The text was updated successfully, but these errors were encountered: