Springboot HikariCP

Fabio Ebner picture Fabio Ebner · Jun 26, 2017 · Viewed 6.9k times · Source

I using springboot with HikariCP, but after a while my app crash and I got the error:

org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
...

Caused by: org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection

....
Caused by: java.sql.SQLTransientConnectionException: HikariPool-6 - Connection is not available, request timed out after 30000ms.

This is my aplication.properties

spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.url=jdbc:postgresql://localhost:5432/db_dnaso
#spring.datasource.url=jdbc:postgresql://172.16.1.10:5432/db_dnaso
spring.datasource.username=postgres
spring.datasource.password=dna44100
spring.datasource.driver-class-name=org.postgresql.Driver

So I have a lot of save, find and anothers access to DB, how can I visualize how method are blocking my connection?

tks

Answer

Smit K picture Smit K · Aug 7, 2017

It looks like your your database server is running out of connection. Default value for property maximumPoolSize in Hikari is 10. That means it will try to create 10 connection on server startup and it will not start if not able to acquire 10 connection or may fail if your db server pool size having less connection in the pool as you are creating using Hikari configuration. If you are able to start Spring Boot server and then facing this issue then try enabling leakDetectionThreshold and check which connection is taking more time and not returning to Hikari pool .

spring:
  datasource:        
    hikari:                    
      leak-detection-threshold: 2000