我们运行一个连接到远程服务器上的MySQL的应用程序,并在我们的应用程序日志中看到了通信链接失败。日志也说
从服务器成功收到的最后一个数据包为0 几毫秒之前。成功发送到服务器的最后一个数据包是 0毫秒前。
所以我们认为这个异常没有发生,因为服务器杀死了一个陈旧的连接。这是完整的堆栈跟踪:
Caused by: com.mysql.cj.core.exceptions.CJCommunicationsException: Communications link failure
The last packet successfully received from the server was 0 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
at sun.reflect.GeneratedConstructorAccessor19.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:54)
at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:93)
at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:133)
at com.mysql.cj.core.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:149)
at com.mysql.cj.mysqla.io.MysqlaProtocol.readPacket(MysqlaProtocol.java:446)
at com.mysql.cj.mysqla.io.MysqlaProtocol.checkErrorPacket(MysqlaProtocol.java:637)
at com.mysql.cj.mysqla.io.MysqlaProtocol.sendCommand(MysqlaProtocol.java:581)
at com.mysql.cj.mysqla.io.MysqlaProtocol.sqlQueryDirect(MysqlaProtocol.java:865)
at com.mysql.cj.mysqla.MysqlaSession.sqlQueryDirect(MysqlaSession.java:452)
at com.mysql.cj.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2036)
... 22 more
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.cj.core.io.FullReadInputStream.readFully(FullReadInputStream.java:61)
at com.mysql.cj.mysqla.io.SimplePacketReader.readHeader(SimplePacketReader.java:60)
at com.mysql.cj.mysqla.io.TimeTrackingPacketReader.readHeader(TimeTrackingPacketReader.java:48)
at com.mysql.cj.mysqla.io.MultiPacketReader.readHeader(MultiPacketReader.java:51)
at com.mysql.cj.mysqla.io.MysqlaProtocol.readPacket(MysqlaProtocol.java:440)
我们对如何部分调试这一点毫无头绪,因为我们不知道任何一致地重现此错误的步骤。我们使用的是HikariCP的默认设置。我们的mysql管理员告诉我们他们确实杀死了闲置超过5分钟的连接,但从上面看,我们的连接似乎没有闲置那么久。
我们的管理员还声称发生异常时没有服务器重启。客户端应该如何处理服务器重启或网络故障?客户端是需要自己实现重试逻辑还是开箱即用?任何指针都赞赏。