nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link fai

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link fai相关的知识,希望对你有一定的参考价值。

 今天晚上一个财务子系统上线,部署完成后,测试反馈程序会抽风,一会儿正常,一会儿异常,报如下错误:

nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link fai

 

通过查找资料,可能是wait_timeout设置过小导致的,尝试加大wait_timeout的值后,系统恢复正常。

更改过程如下:

##查看MySQL配置
[email protected]:mysql.sock [finance]>show global variables like ‘wait_timeout‘; 
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout  | 10    |
+---------------+-------+
1 row in set (0.01 sec)
[email protected]:mysql.sock [finance]>show global variables like ‘%interactive_timeout%‘;
+---------------------+-------+
| Variable_name       | Value |
+---------------------+-------+
| interactive_timeout | 28800 |
+---------------------+-------+
 
##先修改全局的值为300,重启后将恢复原值
[email protected]:mysql.sock [finance]>set global wait_timeout=300;
[email protected]:mysql.sock [finance]>show global variables like ‘wait_timeout‘;
+--------------------------+----------+
| Variable_name            | Value    |
+--------------------------+----------+
| wait_timeout             | 300      |
+--------------------------+----------+
 
##修改my.cnf,保证MySQL重启后依然生效
[mysqld]  
wait_timeout=300  
 
## wait_timeout扩展
MySQL服务器默认的“wait_timeout”默认是28800秒即8小时,意味着如果一个连接的空闲时间超过8个小时,MySQL将自动断开该连接,而连接池却认为该连接还是有效的(因为并未校验连接的有效性),当应用申请使用该连接时,就会导致上面的报错。
解决方法:
 
修改my.cnf: 
[mysqld]  
wait_timeout=31536000  
interactive_timeout=31536000   
将过期时间修改为1年。 
 
Error Log日志如下:
技术分享
The last packet successfully received from the server was 9,369 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.
; SQL []; Communications link failure
 
The last packet successfully received from the server was 9,369 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
 
The last packet successfully received from the server was 9,369 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:98)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
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.$Proxy11.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
at com.sun.proxy.$Proxy12.searchRules(Unknown Source)
at com.tianlian.order.server.finance.service.impl.poundage.WPOSPoundageServiceImpl.searchRules(WPOSPoundageServiceImpl.java:55)
at com.tianlian.order.server.finance.service.impl.poundage.WPOSPoundageServiceImpl$$FastClassBySpringCGLIB$$aec2fff5.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 com.alibaba.druid.support.spring.stat.DruidStatInterceptor.invoke(DruidStatInterceptor.java:72)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
at com.tianlian.order.server.finance.service.impl.poundage.WPOSPoundageServiceImpl$$EnhancerBySpringCGLIB$$db4e378e.searchRules(<generated>)
at com.alibaba.dubbo.common.bytecode.Wrapper0.invokeMethod(Wrapper0.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.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.rpc.filter.TimeoutFilter.invoke(TimeoutFilter.java:42)
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.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.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:82)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Error log


以上是关于nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link fai的主要内容,如果未能解决你的问题,请参考以下文章

nested exception is io.lettuce.core.RedisCommandTimeoutException

nested exception is io.lettuce.core.RedisCommandTimeoutException

nested exception is org.apache.ibatis.reflection.ReflectionExceptio

Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jacks

HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.GenericJDBC

随手记录关于Factory method 'eurekaApplicationInfoManager' threw exception; nested exception is j(代