IHttpClientFactory 间歇性失败并在 .NET Core 3.1 中出现套接字异常

问题描述

使用 .NET Core 3.1 的 WebAPI 应用程序以 HAProxy 作为前端向应用程序发送 POST 调用。应用程序托管在 2 个 Windows 核心服务器上,每天处理大约 50k 次调用。 21 秒后 API 调用间歇性失败。

IHttpClientFactory 已按照以下 Microsoft 文档实施。

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1

客户端抓包显示客户端,服务器端的SYN和ACK成功后发送RST。

PacketCapture

异常:

A connection attempt Failed because the connected party did not properly respond after a period of time,or an established connection Failed because the connected host has Failed to respond.
System.Net.sockets.socketException (10060): A connection attempt Failed because the connected party did not properly respond after a period of time,or an established connection Failed because the connected host has Failed to respond.
   at System.Net.Http.ConnectHelper.ConnectAsync(String host,Int32 port,CancellationToken cancellationToken)
   at System.Net.Http.ConnectHelper.ConnectAsync(String host,CancellationToken cancellationToken)
   at System.Net.Http.httpconnectionPool.ConnectAsync(HttpRequestMessage request,Boolean allowHttp2,CancellationToken cancellationToken)
   at System.Net.Http.httpconnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request,CancellationToken cancellationToken)
   at System.Net.Http.httpconnectionPool.GethttpconnectionAsync(HttpRequestMessage request,CancellationToken cancellationToken)
   at System.Net.Http.httpconnectionPool.SendWithRetryAsync(HttpRequestMessage request,Boolean doRequestAuth,CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request,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.FinishSendAsyncBuffered(Task`1 sendTask,HttpRequestMessage request,CancellationTokenSource cts,Boolean disposeCts)
   at SCMdatamartAPI.Elastic.ElasticclientService.IndexElasticDocument(Object json,String indexName)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...