-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
HttpClient on .net core3.0 and 5.0 with different responses #54807
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Testing code: using System;
using System.Net.Http;
namespace Demo.SDK5._0
{
class Program
{
static void Main(string[] args)
{
var client = new HttpClient();
//var resp = client.GetAsync("https://sfapi-sbox.sf-express.com/std/service").Result;
var resp = client.GetAsync("https://demo.identityserver.io/.well-known/openid-configuration").Result;
Console.WriteLine(resp.Content.ReadAsStringAsync().Result);
Console.ReadKey();
}
}
} |
Tagging subscribers to this area: @dotnet/ncl Issue DetailsHi there, Next I used the same code on two computers, using the company network and 4G network to test The following two links PC [001] OS Name: Windows, OS Version: 10.0.19042, RID: win10-x64 PC[002] =>Restore factory mode OS Name: Windows, OS Version: 10.0.18362, RID: win10-x64 Link1:https://sfapi-sbox.sf-express.com/std/service Link2:https://demo.identityserver.io/.well-known/openid-configuration 1.Using the company network
2.Using the 4G network
|
@jchhh912 will you get the same exception if you use packet capture tool like Wireshark? |
Triage: @antonfirsov thinks it may be IPv6 differences -- there is workaround he is going to post here. |
@jchhh912 this might be caused by issues with IPV6 and/or dual-stack socket support in your corpnet or the McAffee proxy. Since .NET 5.0, public HttpClient CreateWorkaroundClient()
{
SocketsHttpHandler handler = new SocketsHttpHandler
{
ConnectCallback = IPv4ConnectAsync
};
return new HttpClient(handler);
static async ValueTask<Stream> IPv4ConnectAsync(SocketsHttpConnectionContext context, CancellationToken cancellationToken)
{
// By default, we create dual-mode sockets:
// Socket socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.NoDelay = true;
try
{
await socket.ConnectAsync(context.DnsEndPoint, cancellationToken).ConfigureAwait(false);
return new NetworkStream(socket, ownsSocket: true);
}
catch
{
socket.Dispose();
throw;
}
}
} This overrides |
Thanks, this is useful and I was wondering if this would be fixed in 6.0? |
I'm sorry, but I can't use Wireshark due to my company's IT policy, but if there is another suitable method, I'd be happy to provide you with information. |
@jchhh912 I'm not familiar with the McAfee software mentioned, I don't know what does the log in the screenshot mean. For us the most important question here is if the workaround code in #54807 (comment) changes anything while keeping your company software turned on. |
@antonfirsov Yes, my application works fine after using it, but do I need to come back and change my code if my .net core version continues to be upgraded later? |
We plan to implement this in .NET 6: #47583 ... as a workaround and escape route for environments where IPv6 does not work properly (like yours - likely caused by MacAfee SW). |
@jchhh912 .NET uses IPv6 dual-stack sockets very extensively, switching to them in HttpClient was a natural step, we don't plan to revert it. In our experience, IPv6 works 99.9% of the time, when not, it's typically a problem with IPv6 support within your IT infrastructure. We recommend to raise an issue against your IT department. If they can't resolve it for some reason, #47583 will provide an easy workaround (disabling IPv6 globally within your .NET app). |
Fixes #47583. Resolves #52287, #54807 and similar issues, without changing customer application code. Introduces an AppContext switch `System.Net.DisableIPv6` and environment variable `DOTNET_SYSTEM_NET_DISABLEIPV6` to emulate the lack of OS-level IPv6 support. This is useful to workaround dual-stack socket issues when the OS reports support of IPv6, but some other underlying infrastructure element (typically VPN) doesn't function well with IPv6 request. For consistency, this switch also impacts NameResolution and Ping, not only Sockets.
Hi there,
I see a few cases of the same error as mine in Issues, and I thought I should do something to give you more information to make changes to this issue.
Next I used the same code on two computers, using the company network and 4G network to test The following two links
PC [001]
OS Name: Windows, OS Version: 10.0.19042, RID: win10-x64


Macafee Version:
Pulse Secure Version:
PC[002] =>Restore factory mode
OS Name: Windows, OS Version: 10.0.18362, RID: win10-x64
Link1:https://sfapi-sbox.sf-express.com/std/service
Link2:https://demo.identityserver.io/.well-known/openid-configuration
1.Using the company network
2.Using the 4G network
The text was updated successfully, but these errors were encountered: