alibaba / druid

阿里云计算平台DataWorks(https://help.aliyun.com/document_detail/137663.html) 团队出品,为监控而生的数据库连接池
https://github.com/alibaba/druid/wiki
Apache License 2.0
27.96k stars 8.58k forks source link

Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost. #2784

Open jacarrichan opened 6 years ago

jacarrichan commented 6 years ago

也不知道是不是 druid问题,还是请各位大神帮忙看下 ,下面贴上堆栈。

配置信息如下

+--------------------------------+------------------------------------------------------------+-------------------------------------------------------------+
|Identity                        |1317963297                                                  |775423528                                                    |
+--------------------------------+------------------------------------------------------------+-------------------------------------------------------------+
|Name                            |jdbc:mysql://192.168.0.100:8066/china                      |jdbc:mysql://192.168.0.16:8066/china                          
|DbType                          |mysql                                                       |mysql                                                        |
|DriverClassName                 |com.mysql.jdbc.Driver                                       |com.mysql.jdbc.Driver                                        |
|URL                             |jdbc:mysql://192.168.0.100:8066/china                      |jdbc:mysql://192.168.0.16:8066/china                          |
|UserName                        |etestp                                                       |eunep                                                        |
|FilterClassNames                |[com.alibaba.druid.filter.config.ConfigFilter]              |[com.alibaba.druid.filter.config.ConfigFilter]               |
|WaitThreadCount                 |0                                                           |0                                                            |
|NotEmptyWaitCount               |13                                                          |17                                                           |
|NotEmptyWaitMillis              |11902                                                       |123376                                                       |
|PoolingCount                    |2                                                           |2                                                            |
|PoolingPeak                     |50                                                          |50                                                           |
|PoolingPeakTime                 |2018-08-29 17:41:12                                         |2018-08-29 17:41:15                                          |
|ActiveCount                     |0                                                           |0                                                            |
|ActivePeak                      |3                                                           |3                                                            |
|ActivePeakTime                  |2018-08-29 18:01:12                                         |2018-08-29 18:26:47                                          |
|InitialSize                     |50                                                          |50                                                           |
|MinIdle                         |30                                                          |30                                                           |
|MaxActive                       |50                                                          |50                                                           |
|QueryTimeout                    |0                                                           |0                                                            |
|TransactionQueryTimeout         |0                                                           |0                                                            |
|LoginTimeout                    |0                                                           |0                                                            |
|ValidConnectionCheckerClassName |com.alibaba.druid.pool.vendor.MySqlValidConnectionChecker   |com.alibaba.druid.pool.vendor.MySqlValidConnectionChecker    |
|ExceptionSorterClassName        |com.alibaba.druid.pool.vendor.MySqlExceptionSorter          |com.alibaba.druid.pool.vendor.MySqlExceptionSorter           |
|TestOnBorrow                    |true                                                        |true                                                         |
|TestOnReturn                    |false                                                       |false                                                        |
|TestWhileIdle                   |true                                                        |true                                                         |
|DefaultAutoCommit               |true                                                        |true                                                         |
|DefaultReadOnly                 |                                                            |                                                             |
|DefaultTransactionIsolation     |                                                            |                                                             |
|LogicConnectCount               |51430                                                       |51312                                                        |
|LogicCloseCount                 |51391                                                       |51268                                                        |
|LogicConnectErrorCount          |0                                                           |0                                                            |
|PhysicalConnectCount            |61                                                          |64                                                           |
|PhysicalCloseCount              |20                                                          |20                                                           |
|PhysicalConnectErrorCount       |0                                                           |0                                                            |
|ExecuteCount                    |110757                                                      |110761                                                       |
|ErrorCount                      |0                                                           |1                                                            |
|CommitCount                     |25843                                                       |25708                                                        |
|RollbackCount                   |81                                                          |64                                                           |
|PSCacheAccessCount              |0                                                           |0                                                            |
|PSCacheHitCount                 |0                                                           |0                                                            |
|PSCacheMissCount                |0                                                           |0                                                            |
|StartTransactionCount           |22333                                                       |22162                                                        |
|TransactionHistogram            |[0, 12108, 9383, 809, 32, 1, 0]                             |[0, 11908, 9506, 686, 57, 4, 0]                              |
|ConnectionHoldTimeHistogram     |[0, 0, 0, 0, 0, 0, 0, 0]                                    |[0, 0, 0, 0, 0, 0, 0, 0]                                     |
|RemoveAbandoned                 |false                                                       |false                                                        |
|ClobOpenCount                   |0                                                           |0                                                            |
+--------------------------------+------------------------------------------------------------+-------------------------------------------------------------+

PS 获取上述信息的命令: java -cp "./druid-1.0.14.jar:$JAVA_HOME/lib/tools.jar" com.alibaba.druid.support.console.DruidStat -ds -detail 13813

异常堆栈如下

### Error getting a new connection.  Cause: java.sql.SQLException: connection holder is null
### Cause: java.sql.SQLException: connection holder is null
; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; connection holder is null; nested exception is java.sql.SQLException: connection holder is null
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
at com.sun.proxy.$Proxy71.getConnection(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.getConnection(SqlSessionTemplate.java:332)
at com.xxxxxx.dao.service.DipperDaoService.beginTransaction(DipperDaoService.java:73)
at com.xxxxxx.dao.service.DipperDaoService$$FastClassBySpringCGLIB$$db6a18fd.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
......
at com.alibaba.dubbo.common.bytecode.Wrapper2.invokeMethod(Wrapper2.java)
at com.alibaba.dubbo.rpc.proxy.javassist.JavassistProxyFactory$1.doInvoke(JavassistProxyFactory.java:46)
at com.alibaba.dubbo.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:72)
at com.alibaba.dubbo.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:53)
at com.xxxxxx.dubbo.filter.LoggerFilter.invoke(LoggerFilter.java:45)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
at com.xxxxxx.dubbo.filter.ExceptionFilter.invoke(ExceptionFilter.java:32)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
at com.xxxxxx.dubbo.filter.DipperFilter.invoke(DipperFilter.java:34)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
at com.alibaba.dubbo.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:64)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
at com.alibaba.dubbo.monitor.support.MonitorFilter.invoke(MonitorFilter.java:75)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
at com.alibaba.dubbo.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:42)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
at com.alibaba.dubbo.rpc.protocol.dubbo.filter.TraceFilter.invoke(TraceFilter.java:78)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
at com.alibaba.dubbo.rpc.filter.ContextFilter.invoke(ContextFilter.java:60)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
at com.alibaba.dubbo.rpc.filter.GenericFilter.invoke(GenericFilter.java:112)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
at com.alibaba.dubbo.rpc.filter.ClassLoaderFilter.invoke(ClassLoaderFilter.java:38)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
at com.alibaba.dubbo.rpc.filter.EchoFilter.invoke(EchoFilter.java:38)
at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:91)
at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol$1.reply(DubboProtocol.java:108)
at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.handleRequest(HeaderExchangeHandler.java:84)
at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler.received(HeaderExchangeHandler.java:170)
at com.alibaba.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:52)
at com.alibaba.dubbo.remoting.transport.dispather.ChannelEventRunnable.run(ChannelEventRunnable.java:82)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: connection holder is null
at com.alibaba.druid.pool.DruidPooledConnection.checkStateInternal(DruidPooledConnection.java:1107)
at com.alibaba.druid.pool.DruidPooledConnection.checkState(DruidPooledConnection.java:1100)
at com.alibaba.druid.pool.DruidPooledConnection.getAutoCommit(DruidPooledConnection.java:705)
at com.xxxxxx.dao.ConnectionDecoratorProxy.getAutoCommit(ConnectionDecoratorProxy.java:131)
at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:82)
at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67)
at org.apache.ibatis.session.defaults.DefaultSqlSession.getConnection(DefaultSqlSession.java:227)
at sun.reflect.GeneratedMethodAccessor583.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
... 52 common frames omitted
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 5,857 milliseconds ago.  The last packet sent successfully to the server was 3,757 milliseconds ago.
at sun.reflect.GeneratedConstructorAccessor122.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1137)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3715)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3604)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4149)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2840)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1302)
at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:2931)
at com.alibaba.druid.filter.FilterAdapter.preparedStatement_execute(FilterAdapter.java:1058)
at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:2929)
at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:131)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:493)
at sun.reflect.GeneratedMethodAccessor490.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:62)
at com.sun.proxy.$Proxy85.execute(Unknown Source)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:59)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:73)
at sun.reflect.GeneratedMethodAccessor498.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62)
at com.sun.proxy.$Proxy83.query(Unknown Source)
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:60)
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:96)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:77)
at sun.reflect.GeneratedMethodAccessor497.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)
at org.spoon.crypt.interceptor.EncryptInterceptor.intercept(EncryptInterceptor.java:48)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:60)
at com.sun.proxy.$Proxy82.query(Unknown Source)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:66)
at sun.reflect.GeneratedMethodAccessor516.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
at com.sun.proxy.$Proxy71.selectOne(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:163)
... 36 common frames omitted
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.jdbc.MysqlIO.readFully(MysqlIO.java:3161)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3615)
... 104 common frames omitted
gMan1990 commented 5 years ago

我这也有这问题,大部分情况正常执行,偶尔The last packet successfully received from the server was错误

jacarrichan commented 5 years ago

你这排除掉8小时的可能了吗?

gMan1990 commented 5 years ago

@jacarrichan 什么8小时?

jacarrichan commented 5 years ago

@gMan1990 mysql 的8小时问题 啊

yaoyuanyy commented 5 years ago

@jacarrichan mysql 的8小时问题是什么

xiaoyifang commented 5 years ago

已经配置TestOnBorrow true了,应该跟8个小时没关系。 我这里也有遇到druid的这个错误。我这里的配置,已经把8个小时的改掉了。

jacarrichan commented 5 years ago

@gMan1990 我也是偶尔有这个问题

Felixmao commented 5 years ago

同样出现这个问题, 开启心跳检测 keepAlive
升级到最新的druid, 配置min-evictable-idle-time-millis 和 max-evictable-idle-time-millis 甚至升级mysql-connector-java 均不能解决,如果设置 removeAbandoned=true, 则atomikos会报错,猜测是druid生效了,但是没有通知到atomikos 迷茫中。。。

rocky225 commented 5 years ago

问题是否解决了 @jacarrichan

jacarrichan commented 5 years ago

@rocky225 是什么问题啊?

rocky225 commented 5 years ago

@jacarrichan 我感觉是Mysql(Ver 5.6.10)的问题, 我配置文件的wait_timeout = 20. 但show variables 显示的 wait_timeout = 28800 修改后暂时没有出现这个问题, 再观察几天看看

DavenZhangcq commented 5 years ago

我的也是同样的,把druid换到是新版本也是报。connection holder is null

ioandy commented 5 years ago

同样问题,各种方法试了一遍,没有解决,请问各位搞定了没?

shuiZzz commented 5 years ago

atomikos的配置貌似跟druid的没有对齐…有大佬解决了没啊?

git10135405 commented 3 years ago

楼主解决了吗

DavenZhangcq commented 3 years ago

目前已处理了,改的mysql参数和调整的代码?

在 2021-03-02 11:14:35,"git10135405" @.***> 写道:

楼主解决了吗

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

git10135405 commented 3 years ago

能具体说说?