有一些相关的问题,但并不完全类似,因此我就发布了这个问题-- Description:这个警告(SQLSTATE(08S01),ErrorCode(0))是断断续续地立即出现的,之后在springboot java代码中出现异常,同时从数据库中获取(选择查询)记录,其中它使用了springboot jparepository概念。
下面是警告的异常跟踪
com.zaxxer.hikari.pool.ProxyConnection:::ProxyConnection.java:::checkException:::182:::HikariPool-1 - Connection com.mysql.cj.jdbc.ConnectionImpl@ee48bb3 marked as broken because of SQLSTATE(08S01), ErrorCode(0)
com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was 949,021 milliseconds ago. The last packet sent successfully to the server was 949,022 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
at com.mysql.cj.jdbc.ConnectionImpl.setReadOnlyInternal(ConnectionImpl.java:2161)
at com.mysql.cj.jdbc.ConnectionImpl.setReadOnly(ConnectionImpl.java:2145)
at com.zaxxer.hikari.pool.ProxyConnection.setReadOnly(ProxyConnection.java:423)
at com.zaxxer.hikari.pool.HikariProxyConnection.setReadOnly(HikariProxyConnection.ja
在上述警告之后,服务代码立即失败,原因是在使用springboot jparepository的情况下出现了以下异常。
:::D3931305D3A84D82AACF29594A0432C8::::::Monitor:::com.zaxxer.hikari.pool.ProxyLeakTask:::ProxyLeakTask.java:::cancel:::91:::Previously reported leaked connection com.mysql.cj.jdbc.ConnectionImpl@ee48bb3 on thread http-nio-9090-exec-69 was returned to the pool (unleaked)
2021-09-07 **21:39:52,100:::ERROR:::D3931305D3A84D82AACF29594A0432C8:::saveRunConfigurations:::388:::Could not open JPA EntityManager for transaction; nested exception is org.hibernate.TransactionException: JDBC begin transaction failed:
org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is org.hibernate.TransactionException: JDBC begin transaction failed:**
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:448)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.startTransaction(AbstractPlatformTransactionManager.java:400)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:572)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:360)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
.
.
下面是mysql的HikariCp配置和超时值
spring.datasource.hikari.maximumPoolSize=150
spring.datasource.hikari.minimumIdle=20
spring.datasource.hikari.idleTimeout=600000
spring.datasource.hikari.connectionTimeout=900000
spring.datasource.hikari.maxLifetime=1000000
spring.datasource.hikari.validationTimeout=30000
spring.datasource.hikari.connectionTestQuery=SELECT 1
spring.datasource.hikari.leakDetectionThreshold=90000
---
MySQL [(none)]> SHOW GLOBAL VARIABLES LIKE "%wait%";
+---------------------------------------------------+----------+
| Variable_name | Value |
+---------------------------------------------------+----------+
| innodb_fatal_semaphore_wait_threshold | 600 |
| innodb_lock_wait_timeout | 50 |
| innodb_spin_wait_delay | 6 |
| lock_wait_timeout | 31536000 |
| performance_schema_events_waits_history_long_size | 10000 |
| performance_schema_events_waits_history_size | 10 |
| shutdown_wait_connection_timeout | 500 |
| thread_pool_batch_wait_timeout | 10000 |
| wait_timeout | 180 |
MySQL [(none)]> SHOW VARIABLES LIKE "%timeout%";
+----------------------------------+----------+
| Variable_name | Value |
+----------------------------------+----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| have_statement_timeout | YES |
| innodb_flush_log_at_timeout | 1 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 28800 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 120 |
| net_write_timeout | 240 |
| rpl_stop_slave_timeout | 31536000 |
| shutdown_wait_connection_timeout | 500 |
| slave_net_timeout | 60 |
| tcp_linger_timeout | 10 |
| thread_pool_batch_wait_timeout | 10000 |\
| wait_timeout | 28800 |
因为这个问题是关于PROD env的,所以我必须在Lower上复制这个问题,从而找到确切的RCA。
reproduce
值的情况。
对于找到这个问题的确切原因和如何重现这个问题的建议,这将有很大的帮助。
发布于 2021-10-14 06:42:38
似乎您在服务器上配置了某种空闲连接超时。您应该能够通过配置连接池来每隔X秒进行连接验证查询,从而解决这一问题。查看文档,看起来keepaliveTime
是您应该设置的设置,例如300000 (ms中的5分钟):https://github.com/brettwooldridge/HikariCP
https://stackoverflow.com/questions/69394504
复制相似问题