Skip to content

HikariPool-1 – Connection is not available, request timed out after 30138ms.

Error –

Caused by: java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30138ms.
at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:583)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:186)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:145)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:85)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
at org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:38)
at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:113)

Environment –

  • Spring Boot version 2 and above
  • Java version 8 and above
  • All HikariCP versions

Root cause –

HikariCP connection pool is not able connect with database. There can be many root causes for this.
If you are required to be connnected with VPN to access machine hosted database then timed out could occure.
If database has heavy load and not able to provide connection as requested by user. Default timeout in HikariCP is 30000 ms (30 seconds)

Solution –

Check connection time out set for HikariCP connection pool.

If the values are set in code

HikariConfig config = new HikariConfig();
config.setConnectionTimeout(50000); // values are in milli seconds

If the values are set in application.yml

spring:
 datasource:
  hikari:
   connectionTimeout: 50000

Important Note –

By increasing the timeout may solve the symptom but almost certainly does not address the root problem. Make sure you are analyzing it very well why old timeout is not enough to get new connection.

Do you have another solution?

The solution provided above is based on the scenario our one of the developers/contributors faced. If you faced the same issue and found any other root cause then please share your solution in the comment section below. We will add the solution in this article.

Leave a Reply

Your email address will not be published. Required fields are marked *