Repository navigation
Httpclient perfectly work on 3.1 but timeout in .net 5 #47267
Copy link
Copy link
Closed
Labels
Milestone
Description
Describe the bug
I made a project on Asp.net Core 3.1 which is automatically fetching some information from another API (which is only accessible using VPN client) it's work perfectly.
Now I converted my project to .net 5 suddenly I am unable to get a response from that API.
giving flowing error every time.
System.Net.Http.HttpRequestException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (192.168.1.47:80)
---> System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|283_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.DefaultConnectAsync(SocketsHttpConnectionContext context, CancellationToken cancellationToken)
at System.Net.Http.ConnectHelper.ConnectAsync(Func`3 callback, DnsEndPoint endPoint, HttpRequestMessage requestMessage, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.ConnectHelper.ConnectAsync(Func`3 callback, DnsEndPoint endPoint, HttpRequestMessage requestMessage, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)
at BizClientHandler.Controllers.RequestRedirectController.Post(String value) in D:\MIBS\DocterBiz\BizClientHandler\BizClientHandler\BizClientHandler\Controllers\RequestRedirectController.cs:line 39
at lambda_method6(Closure , Object )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
HEADERS
=======
Connection: keep-alive
Accept: text/plain
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie: .AspNetCore.Culture=c%3Den-IN%7Cuic%3Den-US; .AspNetCore.Antiforgery.oQg8oV5EXPo=CfDJ8PWcNQnbsmR..................................FTgP3EgLm1Q
Host: localhost:54321
Referer: http://localhost:54321/swagger/index.html
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36 Edg/87.0.664.75
Origin: http://localhost:54321
Content-Length: 0
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
I tried everything but the result is the same. (Not working)
1.
AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false); HttpClient client = new HttpClient(new SocketsHttpHandler()
{
KeepAlivePingDelay = Timeout.InfiniteTimeSpan,
KeepAlivePingTimeout = Timeout.InfiniteTimeSpan,
KeepAlivePingPolicy = HttpKeepAlivePingPolicy.Always
}); WebRequest request = WebRequest.Create(value);
WebResponse response = request.GetResponse();for another try, I created another test project from scratch in asp.net core 3.1 and it's working.
and another same project created in asp.net core 5 it's not working.
Other info
I am not getting ping from the server where API is hot because of the VPN client.
but it's perfectly working on Asp.net core 3.1, In browser, and POSTMAN also but not in .net 5
Reactions are currently unavailable

Activity
antonfirsov commentedon Jan 21, 2021
This is most likely related to #44686, sharing the same root cause.
.NET 5 switched to use dual-stack sockets for
HttpClient, meaning that IPV6 sockets are used for both ipv4 and ipv6 requests. Your VPN (client? network?) most likely doesn't have proper IPV6 and/or dual-stack support.Can you please try the workaround in #44686 (comment)?
Also: if you could provide some info about IPV6 support in your VPN environment, it would be very helpful for us to triage the issue.
antonfirsov commentedon Jan 21, 2021
After a quick google search for "pulse secure IPV6" I found this:
https://docs.pulsesecure.net/WebHelp/Content/PCS/PCS_AdminGuide_8.2/IPv6%20Support%20and%20Limitations.htm
@NitishGawde do you think you are hitting any of the limitations listed there?
NitishGawde commentedon Jan 22, 2021
#44686 (Comment) working for me. I think the problem is a dule socket.
Thanks @antonfirsov
antonfirsov commentedon Jan 28, 2021
This workaround is not sufficient for users who don't have direct control over their
HttpClientinstances, therefore we are considering further improvements here.@NitishGawde I'm wondering if you can help us by trying to get more info about why doesn't dual-stack work in your VPN. (Maybe by asking your IT department?) I'm happy to contact you privately if it's better for you.
karelz commentedon Feb 2, 2021
@NitishGawde will you be able to help us gather more info about your environment?
NitishGawde commentedon Feb 3, 2021
@karelz and @antonfirsov what information do you need from my end.
I will happy to share any information which is in my authority.
please provide a list of things you need.
karelz commentedon Feb 10, 2021
@NitishGawde we need to understand why dual-sockets are not working correctly in your environment -- is it VPN misconfiguration? Old version? Or is that by design in your VPN client? (known limitation)
Is it managed by you or your IT department? Are you able to experiment? (e.g. small C++ apps to try out what works and what doesn't)
ManickaP commentedon Feb 18, 2021
Triage: seems like workaround worked. There's nothing actionable at the moment, closing.