【问题标题】:How to fix Socket Error: connection reset by peer如何修复套接字错误:对等方重置连接
【发布时间】:2020-06-09 07:14:46
【问题描述】:

我运行一个项目 .NET,在 dev.azure 中有 Quazrt Job。我在 mysql db 中的作业查询和插入/更新数据出现错误:

job executesqljob failed with exception: parameters: refire = false, unschedulefiringtrigger = false, unschedulealltriggers = false 
 quartz.jobexecutionexception: job threw an unhandled exception.
 ---> quartz.schedulerexception: job threw an unhandled exception.
 ---> system.net.sockets.socketexception: connection reset by peer
   at mysqlconnector.protocol.serialization.socketbytehandler.writebytesasync(arraysegment  data, iobehavior iobehavior) in c:\projects\mysqlconnector\src\mysqlconnector\protocol\serialization\socketbytehandler.cs:line 90
--- end of stack trace from previous location where exception was thrown ---
   at mysqlconnector.utilities.valuetaskextensions.continuewith[t,tresult](valuetask valuetask, func continuation) in c:\projects\mysqlconnector\src\mysqlconnector\utilities\valuetaskextensions.cs:line 8
   at mysqlconnector.core.serversession.tryasynccontinuation(task task) in c:\projects\mysqlconnector\src\mysqlconnector\core\serversession.cs:line 1149
   at system.threading.tasks.continuationresulttaskfromresulttask.innerinvoke()
   at system.threading.executioncontext.runinternal(executioncontext executioncontext, contextcallback callback, object state)
--- end of stack trace from previous location where exception was thrown ---
   at system.threading.tasks.task.executewiththreadlocal(task& currenttaskslot)
--- end of stack trace from previous location where exception was thrown ---
   at mysqlconnector.core.textcommandexecutor.executereaderasync(string commandtext, mysqlparametercollection parametercollection, commandbehavior behavior, iobehavior iobehavior, cancellationtoken cancellationtoken) in c:\projects\mysqlconnector\src\mysqlconnector\core\textcommandexecutor.cs:line 72
   at mysql.data.mysqlclient.mysqlcommand.executedbdatareader(commandbehavior behavior) in c:\projects\mysqlconnector\src\mysqlconnector\mysql.data.mysqlclient\mysqlcommand.cs:line 168
   at microsoft.entityframeworkcore.storage.internal.relationalcommand.execute

谁能帮帮我,非常感谢!

【问题讨论】:

    标签: c# mysql sockets jobs quartz.net


    【解决方案1】:

    “由对等方重置连接”表示网络连接的另一端(Azure Database for MySQL,或您用作 MySQL 服务器的任何东西)已关闭连接:https://stackoverflow.com/a/1434506/23633

    您应该检查您的服务器日志以获取有关为什么会发生这种情况的线索。可能是您的连接字符串中的wait_timeout 设置低于ConnectionIdleTimeout,因此空闲连接在池中(在客户端)保持打开的时间比服务器允许它们存活的时间长。

    其次,所有网络都是不可靠的,因此您应该使用Polly 或类似的方法围绕您使用 EF.Core 实施重试策略,以便在失败前多次尝试执行命令。

    【讨论】:

      猜你喜欢
      • 2010-10-24
      • 1970-01-01
      • 2016-04-12
      • 2018-08-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-31
      • 1970-01-01
      相关资源
      最近更新 更多