当前位置:   article > 正文

异常解决经历:The last packet successfully received from the server was 10,010 millisecond

the last packet successfully received from the server was 10,010 millisecond

异常内容大致如下:

  1. The last packet successfully received from the server was 10,011 milliseconds ago. The last packet sent successfully to the server was 10,011 milliseconds ago.
  2. ; Communications link failure
  3. The last packet successfully received from the server was 10,011 milliseconds ago. The last packet sent successfully to the server was 10,011 milliseconds ago.; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
  4. The last packet successfully received from the server was 10,011 milliseconds ago. The last packet sent successfully to the server was 10,011 milliseconds ago.] with root cause
  5. java.net.SocketTimeoutException: Read timed out
  6. at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_342]
  7. at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_342]
  8. at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_342]
  9. at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_342]
  10. at com.mysql.cj.protocol.ReadAheadInputStream.fill(ReadAheadInputStream.java:107) ~[mysql-connector-j-8.0.33.jar!/:8.0.33]
  11. at com.mysql.cj.protocol.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:150) ~[mysql-connector-j-8.0.33.jar!/:8.0.33]
  12. at com.mysql.cj.protocol.ReadAheadInputStream.read(ReadAheadInputStream.java:180) ~[mysql-connector-j-8.0.33.jar!/:8.0.33]
  13. at java.io.FilterInputStream.read(FilterInputStream.java:133) ~[na:1.8.0_342]
  14. at com.mysql.cj.protocol.FullReadInputStream.readFully(FullReadInputStream.java:64) ~[mysql-connector-j-8.0.33.jar!/:8.0.33]
  15. at com.mysql.cj.protocol.a.SimplePacketReader.readHeaderLocal(SimplePacketReader.java:81) ~[mysql-connector-j-8.0.33.jar!/:8.0.33]

先说背景:

我的项目使用mysql+mybatis+Druid。因为多数据源所以,DataSource没有配置在yml,配置在

配置文件中@Configuration。

出现该异常后网上查找资料有各种解决办法。

如:jdbc链接超时时间,超过数据库超时时间,数据库已关闭链接单链接池中的链接仍然存活等等。需要:

修改mysql:wait_timeout、connect_timeout等数据库配置

修改jdbc url参数:&connectTimeout=60000&socketTimeout=60000

均未解决问题,异常中超时时间仍然是10秒钟左右。

最终走debug发现,jdbc url中的connectTimeout、socketTimeout配置未生效,datasource中的配置仍然是默认10秒。

修改配置文件@Configuration中的参数connectTimeout、socketTimeout,解决问题。

总结:出现以上异常与数据库配置无关,与项目中的jdbc配置有关。首先考虑socketTimeout,同时需要观察url参数配置是否生效。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/1014676
推荐阅读
相关标签
  

闽ICP备14008679号