.NET Core 3.1 Websocket错误:指定的网络名称不再可用

Mik*_*e_G 5 websocket .net-core

Microsoft.AspNetCore.Connections.ConnectionResetException: The client has disconnected
 ---> System.Runtime.InteropServices.COMException (0x80070040): The specified network name is no longer available. (0x80070040)
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.Server.IIS.Core.IO.AsyncIOOperation.GetResult(Int16 token)
   at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.ReadBody()
   at System.IO.Pipelines.PipeCompletion.ThrowLatchedException()
   at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
   at System.IO.Pipelines.Pipe.ReadAsync(CancellationToken token)
   at System.IO.Pipelines.Pipe.DefaultPipeReader.ReadAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.ReadAsync(Memory`1 memory, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.IIS.Core.HttpRequestStream.ReadAsyncInternal(Memory`1 buffer, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.DrainAsync(Stream stream, ArrayPool`1 bytePool, Nullable`1 limit, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Mvc.Formatters.NewtonsoftJsonInputFormatter.ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding)
   at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BodyModelBinder.BindModelAsync(ModelBindingContext bindingContext)
   at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(ActionContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value)
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerBinderDelegateProvider.<>c__DisplayClass0_0.<<CreateBinderDelegate>g__Bind|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   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.<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__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at MyApp.Utility.Extensions.<>c.<<UseMyAppSocket>b__0_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
Run Code Online (Sandbox Code Playgroud)

我有一些客户抱怨使用 websocket 与我的 web 服务断开连接。他们使用 JS Angular 客户端进行连接。我有逻辑客户端在失败时重新连接,但客户报告它从未这样做,或者他们可以看到进行了多次尝试并失败。这个错误是否表明客户端断开连接是由客户端引起的?有什么办法可以确定吗?

dan*_*wag 2

我从https://dba.stackexchange.com/questions/149539/the-specified-network-name-is-no-longer-available中捏了这个,因为它为我解决了问题,但那篇文章并没有容易找到。

\n

问题原来是一些长时间运行的查询,平均需要 20 秒,但有时需要 70 秒,比默认超时时间长,因此抛出异常。

\n

对于长时间运行的查询

\n

为连接到 SQL Server 的应用程序连接字符串实现更长的命令超时值。

\n

例子

\n
<connectionStrings> \n    <add name="webconfigconnectionString" connectionString="server=SQLServerName;database=dbName;uid=u\xe2\x80\x8c\xe2\x80\x8bserName;password=ABC\xe2\x80\x8c\xe2\x80\x8b123;Connect Timeout=120" />\n</connectionStrings>\n
Run Code Online (Sandbox Code Playgroud)\n

这可能不是一个很好的解决方案,但在您弄清楚如何提高查询性能的同时,它至少应该停止失败。

\n

用于 DNS 故障排除

\n

虽然 DNS 不是我的问题,但我已经从 dba.stackexchange 答案中复制了这个,以防它对其他人有帮助。

\n

作为创可贴和故障排除辅助工具,添加并输入应用程序服务器(不是 SQL Server)上的主机文件(位于 c:\\windows\\system32\\drivers\\etc)

\n
SQLServerIPAddress SQLServerName\n
Run Code Online (Sandbox Code Playgroud)\n

例子:

\n
172.16.0.5 ProductionSQLBox\n
Run Code Online (Sandbox Code Playgroud)\n

这样,SQL Server 名称将由主机文件解析,直到您找到名称解析发生的真正问题为止。

\n

确保通过命令行从应用程序服务器 ping SQL 框来测试主机文件。或者,也可以使用控制面板中的 ODBC 管理器创建 DSN 并在那里测试连接。

\n