본문 바로가기

Backend/SpringBoot

Communications link failure

MySQL 오류가 로그에 확인되었다.

Connection com.mysql.jdbc.JDBC4Connection@6b8503b marked as broken because of SQLSTATE(08S01), ErrorCode(0)
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 752,226 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.

 

문제를 확인해 보니, 프로세스가 오래 걸려서 디비 업데이트 하다가 타임아웃 발생한 것이었다.

 

MySQL의 wait_timeout 은 600초(10분)이 기본이었는데, 네트워크 통신하는 프로세스에 지연이 있어 600초를 살짝 넘긴 상황이었다.

 

MySQL의 wait_timeout 을 1800초(30분)로 변경해 주었다.

 

Java 애플리케이션의 application.yml 에 max-lifetime도 같이 수정해 주어야 한다.

기존 550000 밀리초(9분 10초)를 1200000 밀리초(20분) 정도로 수정했다.

jdbc-url: jdbc:mysql:loadbalance://127.0.0.1~~~
          max-lifetime: 550000

 

max-lifetime:

  • 설명: 풀에서 사용되는 커넥션의 최대 수명을 밀리초로 설정합니다. 
  • 주의: max-lifetime 값이 MySQL 서버의 wait_timeout 설정보다 크면 커넥션이 끊어질 수 있습니다.