Skip to content

HikariCP Connection Pool Cannot Recover After MySQL Connection Failure #2374

@ledinhtuyenbkdn

Description

@ledinhtuyenbkdn

HikariCP Connection Pool Cannot Recover After MySQL Connection Failure

Environment

Component Version
Application Spring Boot 3.3.4
Java 17
Connection Pool HikariCP 5.1.0
Database Amazon RDS MySQL 8

Current Configuration

application.yml:

spring:
  datasource:
    hikari:
      poolName: Hikari
      auto-commit: false
      max-pool-size: 30
      minimum-idle: 10
      data-source-properties:
        cachePrepStmts: true
        prepStmtCacheSize: 250
        prepStmtCacheSqlLimit: 2048
        useServerPrepStmts: true

Problem Description

When the application experiences a connection issue to the MySQL server, the connection pool drops to zero and cannot recover automatically. The connection issue only occurs for a short time (several seconds), but the pool still fails to recover. A manual application restart is required to restore functionality.

Logs

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
... 181 more
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:126)
at org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:46)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:127)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:144)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:179)
at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:696)

Caused by: java.sql.SQLTransientConnectionException: Hikari - Connection is not available, request timed out after 30000ms (total=0, active=0, idle=0, waiting=3)
... 178 more
at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:428)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction(HibernateJpaDialect.java:164)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:156)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:129)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:94)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:108)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:58)
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:51)

Caused by: org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection [Hikari - Connection is not available, request timed out after 30000ms]
at java.base/java.lang.Thread.run(Unknown Source)
at org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1282)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)

Expected Behavior

The connection pool should automatically recover and establish new connections after a temporary network/database failure.

Actual Behavior

Connection pool drops to zero (total=0, active=0, idle=0, waiting=3) and does not recover. Application restart is required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions