-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 difference 3.1 vs 5.0. Getting: connection was aborted #52287
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsHi there, I have found strange behavior when moved from 3.1 to 5.0. Runtime: 3.1 - OK Code: namespace WebApplication
{
public class Program
{
public static void Main(string[] args) =>
Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(wb => { wb.UseStartup<Startup>(); }).Build().Run();
}
public class Startup
{
public void ConfigureServices(IServiceCollection services){}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
try
{
var client = new HttpClient();
var resp = await client.GetAsync("https://demo.identityserver.io/.well-known/openid-configuration");
await context.Response.WriteAsync(Environment.Version.ToString() + ": " + resp.StatusCode);
}
catch (Exception ex)
{
await context.Response.WriteAsync(Environment.Version.ToString() + ": " + ex.Message);
}
});
});
}
}
} WebApplication.csproj <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<!--<TargetFramework>netcoreapp3.1</TargetFramework>-->
</PropertyGroup>
</Project> What could be a reason of this behavior on the same machine(just flip TargetFramework)? Thx!
|
can you get packet captures with Wireshark? What is your OS? |
No, I have no chance to download and install something. |
@mikhail-tin is this a consistent or an intermittent error? AFAIK the only socket-level change between 3.1 and 5.0 is our switch to dual-mode sockets. Can you check if this |
@mikhail-tin the code above creates |
It is 100% repro on first request . With CreateWorkaroundClient() no exception, it helps. public static 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:
// var socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
var 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;
}
}
} Thx |
OK, looks like another +1 on DualSockets causing problems ... what is your environment? Is it enterprise setup with some specific firewall? (just out of curiosity) |
No, I have faced it on my machine for development( with firewall, antivirus and proxy). Thx a lot. |
@mikhail-tin can you try disabling these one-by-one without the workaround code? That would be valuable info for us, I'd appreciate. |
I can't do that due corp policies. No ways.. |
@mikhail-tin can you please at least tell us which firewall is used? ... we can then close the issue. |
@karelz, Kaspersky Endpoint Security for Windows |
Thanks! Closing as resolved. |
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 have found strange behavior when moved from 3.1 to 5.0.
The same request in the same environment produces a different result.
Runtime: 3.1 - OK
Runtime 5.0.4 - Exception:
An error occurred while sending the request. -> Unable to read data from the transport connection -> An established connection was aborted by the software in your host machine.
Code:
program.cs
WebApplication.csproj
What could be a reason of this behavior on the same machine(just flip TargetFramework)?
Also I have tried on another machine and both runtime works fine and no exception.
OS: Win 10
Thx!
The text was updated successfully, but these errors were encountered: