본문 바로가기

개발

Failed to validate connection com.mysql.cj.jdbc.ConnectionImpl@3900e5a6 (No operations allowed after connection closed.). Possibly consider using a shorter maxLifetime value.

원인

DB global wait_timeout 값(현재 28800s)과 어플리케이션에 설정한 maxLIfeTime 값과 달라서 발생

해결

1. DB global wait_timeout -> DBCP maxLIfeTime 에 맞추던지

2. DBCP maxLIfeTime -> DB global wait_timeout 에 맞추던지 두 가지 방법이 있음.

hikari 에서는 dba 의견을 따라서 DBCP maxLIfeTime을 DB global wait_timeout 에 맞추는걸 권장함.

hikari 개발자가 남긴 maxLifetime 의 동작 

-> maxLifetime is supported by an individual timer task per-connection. 30 초마다 돌아서 hikari 공식 문서에서는 최소 30000ms (30 seconds)를 권장함.  

-> 30000ms  보다 낮으면 30분으로 자동 세팅 됨.

세팅 된 wait_timeout 값(28800s)에 5초를 뺀 maxLIfeTime 값 0 -> 28795000ms 로 수정 

0으로 설정하면 infinite lifetime이 적용됨(idleTimeout설정 값에 따라 적용 idleTimeout값이 설정되어 있을 경우 0으로 설정해도 무한 lifetime 적용 안됨)

기존 maxLIfeTime에 설정된 0 값 수정 

참고 : 

hikari 개발자가 남긴 maxLifetime 설정 : https://github.com/brettwooldridge/HikariCP/issues/709#issuecomment-384252344https://github.com/brettwooldridge/HikariCP 

(히카리에서 남긴 maxLifeTime 설정방법):

[⏳maxLifetime] This property controls the maximum lifetime of a connection in the pool. An in-use connection will never be retired, only when it is closed will it then be removed. On a connection-by-connection basis, minor negative attenuation is applied to avoid mass-extinction in the pool. We strongly recommend setting this value, and it should be several seconds shorter than any database or infrastructure imposed connection time limit. A value of 0 indicates no maximum lifetime (infinite lifetime), subject of course to the idleTimeout setting. The minimum allowed value is 30000ms (30 seconds). 

Default: 1800000 (30 minutes) |https://github.com/brettwooldridge/HikariCP/issues/709#issuecomment-384252344]

반응형