Fabio Ebner
Fabio Ebner

Reputation: 2783

Springboot HikariCP

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

Upvotes: 10

Views: 17308

Answers (3)

Smit K
Smit K

Reputation: 131

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

Upvotes: 8

Nick.Guo
Nick.Guo

Reputation: 51

In springboot, you can set spring.datasource.hikari.leak-detection-threshold=10000 (in milliseconds) in application.properties.

And the default value for maximumPoolSize is 10. You can change it with spring.datasource.hikari.maximum-pool-size=xx.

Upvotes: 3

brettw
brettw

Reputation: 11114

Enable the leakDetectionThreshold, set to something like 1 minute (60000ms). It is likely that you have a connection leak somewhere ... a connection is borrowed but never closed (returned).

Upvotes: 2

Related Questions