2 years ago
#13547
memoricab
Transactional method connection leak HikariCP jdbctemplate
I experienced a weird issue. It happened only once for a long time living application. And I am trying to diagnose what was the problem.
First of all, the exception is
[Request processing failed; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLTransientConnectionException: hikari_cp - Connection is not available, request timed out after 30000ms.] with root cause
java.sql.SQLTransientConnectionException: hikari_cp - Connection is not available, request timed out after 30000ms.
Above is happened for all db query threads. All of requests to db were failed. I guess according to exception message there was a connection leak? Can you confirm it? (Yes I will enable leak detection)
My second question is what can cause the connection leak? Please see the commented line below.
@Transactional
public SuccessfulLoginAttemptDto recordSuccessfulLogin(Login login) {
Optional<Instant> optionalLastLoginTime = loginRepository.getLastSuccessfulLogin(login.getAccountId());
authNotifierService.loginSuccess(login); //if this is hanging and keeps thread running, would it cause connection leak? Since because of the transactional annotation the connection is not closed until method returns. (this line does not call any db operation)
return smth;
}
Or maybe, can any long running query above cause connection leak? Like, all the connections are busy more than 30 seconds and incoming threads could not find available connection although they waited 30 seconds?
Edit:
@Override
public Optional<LoginAttempt> getLastSuccessfulLogin(Long accountId) {
var params = new MapSqlParameterSource();
params.addValue(PARAM_ACCOUNT_ID, accountId, Types.BIGINT);
try {
return Optional.ofNullable(namedParameterJdbcTemplate.queryForObject(LAST_SUCCESSFUL_LOGIN_ATTEMPT_EVENT,
params, LoginAttempt.rowMapper));
} catch (EmptyResultDataAccessException e) {
return empty();
}
}
Thanks
java
database
spring-boot
jdbctemplate
hikaricp
0 Answers
Your Answer