記一次Could not retrieve transation read-only status server異常

簡述:
技術,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

相關文章
相關標籤/搜索