首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >由于SQLSTATE(08S01)、ErrorCode(0)而标记为断开的连接ErrorCode(0)

由于SQLSTATE(08S01)、ErrorCode(0)而标记为断开的连接ErrorCode(0)
EN

Stack Overflow用户
提问于 2021-09-30 14:58:56
回答 1查看 2.5K关注 0票数 0

有一些相关的问题,但并不完全类似,因此我就发布了这个问题-- Description:这个警告(SQLSTATE(08S01),ErrorCode(0))是断断续续地立即出现的,之后在springboot java代码中出现异常,同时从数据库中获取(选择查询)记录,其中它使用了springboot jparepository概念。

下面是警告的异常跟踪

代码语言:javascript
运行
复制
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的情况下出现了以下异常。

代码语言:javascript
运行
复制
:::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配置和超时值

代码语言:javascript
运行
复制
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

  • tried

  • 尝试了相同的配置,但仍然没有在下env

  • 上直接复制,我认为这是由于wait_timeout值较低,所以尝试将wait_timeout值增加到28800,但在下env

  • 中,
  1. 仍然没有增加负载,这可能是由于防火墙的限制或其他原因,但我并没有确切地了解到如何检查
  2. 尝试过的降低spring.datasource.hikari.maxLifetime=100000

值的情况。

对于找到这个问题的确切原因和如何重现这个问题的建议,这将有很大的帮助。

EN

回答 1

Stack Overflow用户

发布于 2021-10-14 06:42:38

似乎您在服务器上配置了某种空闲连接超时。您应该能够通过配置连接池来每隔X秒进行连接验证查询,从而解决这一问题。查看文档,看起来keepaliveTime是您应该设置的设置,例如300000 (ms中的5分钟):https://github.com/brettwooldridge/HikariCP

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69394504

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档