当前位置:   article > 正文

The last packet successfully received from the server was xxxxx milliseconds ago_hikaricp the last packet successfully received fro

hikaricp the last packet successfully received from the server was 458,946 m
  1. |2024-04-08 15:01:43.912|http-nio-80-exec-81|trace_id=64684ebdaf7585c81b5c3e302303cd5e|ERROR|com.alibaba.druid.pool.DruidPooledStatement|errorCheck|370|CommunicationsException, druid version 1.2.20, jdbcUrl : jdbc:mysql://192.188.200.200:4000/data_uc_sit_0001?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai&tinyInt1isBit=false, testWhileIdle true, idle millis 42977, minIdle 10, poolingCount 8, timeBetweenEvictionRunsMillis 60000, lastValidIdleMillis 42977, driver com.mysql.cj.jdbc.Driver, exceptionSorter com.alibaba.druid.pool.vendor.MySqlExceptionSorter
  2. |2024-04-08 15:01:43.928|http-nio-80-exec-122|trace_id=6ae06d8d93c6ead4e4448a39327d46e7|ERROR|com.alibaba.druid.pool.DruidDataSource|handleFatalError|1988|{conn-59242} discard
  3. |com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
  4. The last packet successfully received from the server was 42,975 milliseconds ago. The last packet sent successfully to the server was 42,976 milliseconds ago.

项目上经常碰到这种问题,特此记录

Druid配置如下

  1. spring:
  2. #配置数据库信息
  3. datasource:
  4. dynamic:
  5. p6spy: false # 默认false,建议线上关闭。
  6. druid:
  7. # 初始连接数
  8. initial-size: 10
  9. # 最小连接池数量
  10. min-idle: 10
  11. # 最大连接池数量
  12. max-active: 10
  13. # 配置获取连接等待超时的时间
  14. max-wait: 60000
  15. # 配置间隔多久进行一次检测,检测需要关闭的空闲连接,单位是毫秒
  16. time-between-eviction-runs-millis: 60000
  17. # 配置一个连接在池中最小生存时间,单位是毫秒
  18. min-evictable-idle-time-millis: 30000
  19. # 配置一个连接在池中最大生存时间,单位是毫秒
  20. max-evictable-idle-time-millis: 90000
  21. # 配置检测连接是否有效
  22. validation-query: select 1

报错中说明上次成功时间是42975ms之前。配置文件中配置的time-between-eviction-runs-millis是60000ms,报错日志中说明testWhileIdle为true。testOnBorrow和testOnReturn默认都为false。testOnBorrow可以避免这个错,但是太占用性能,一般生产环境不能打开。

testWhileIdle为true:代表拿到连接时如果连接空闲时间大于time-between-eviction-runs-millis则进行一次有效性判断。

min-evictable-idle-time-millis配置为30000ms,也就是说连接可能空闲30000ms就关闭了,42975ms也是很有可能关闭的。但是拿到连接后,空闲60000ms(time-between-eviction-runs-millis)才会进行一次空闲检测。理论上time-between-eviction-runs-millis)应当小于等于min-evictable-idle-time-millis

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

闽ICP备14008679号