简述:
技术,spring+mysql....
新项目上线碰到一个问题,具体现象为执行一个方法时报异常,异常信息以下:java
2019-08-20 09:46:08.917[ERROR][Log4jFilter.java:152][DubboServerHandler-192.168.12.156:28104-thread-207] {conn-10670, pstmt-21062} execute error. delete from Dpgd where shco = ? java.sql.SQLException: Could not retrieve transation read-only status server .... at java.lang.Thread.run(Thread.java:745) Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet successfully received from the server was 7,603 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago. ... at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1038)
最开始只看到Could not retrieve transation read-only status server
没看到下面的Communications link failure
,觉得是在代码中手动设置事务状态为只读或者事务回滚,后来查代码也没发现。
当看到Communications link failure
意识到链接异常,但与当前方法链接同一个库的其余方法能够执行成功,因此数据库服务也是正常的。mysql
最终发现缘由:排查的方法中有其余操做发送http请求,稍微有点耗时,但整个方法一分钟之类确定能处理完。spring
分析:
wait_timeout 设置太小,mysql自动丢弃链接,可是程序端没有超时,形成依然在这个被丢弃的链接上执行语句sql
最终解决办法:
设置mysql wait_timeout 参数数据库
show global variables like '%timeout%'; SET GLOBAL wait_timeout=86400;
此处的单位应该是秒。
当前处理的默认值是5
设置86400可能有点极端测试
其余客户都设置了,就这个可能测试环境,配置的时候忘记改参数了。code