Reputation: 79
We have Spring-boot/Hibernate/MYSQL application in our project and use Hikari as the connection pool. After a few minutes when our service is started we found the following problem:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Unable to acquire JDBC Connection; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
Caused by: org.springframework.dao.DataAccessResourceFailureException: Unable to acquire JDBC Connection; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
our config of datasource as follow:
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.connection-timeout=36000
spring.datasource.hikari.maximum-pool-size=2
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.idle-timeout=60000
spring.datasource.hikari.validation-timeout=3000
spring.datasource.hikari.leak-detection-threshold=240000
any one here can give me some clue, Thank you!
Upvotes: 7
Views: 26700
Reputation: 1350
Another cause for this error might be too many open connections for the backend database to handle e.g. when there are too many instances of the service trying to connect at the same time.
Upvotes: 0
Reputation: 7395
You probably have transactions open that you never closed. As time goes by these transactions keep piling up and no new connections can be opened. The connection timeout hits and you get this unable to acquire JDBC connection.
You need to check all your transactional methods and make sure you close/commit them as soon as you are done
I would like to add a specific scenario where we had these issues. This involved a method annotated with @Transactional Database connections open within this method would be inside on open transaction until this method exits. The issue with our program was this was making few HTTP calls and the transactions would be open until the HTTP calls were done. As more calls to this service method were piling up more transactions were in open state than being closed.
Moral of the story: Open transactions, do your stuff quickly and then close the transaction; either implicitly by exiting methods marked @Transactional or by explicit call to transaction close.
Upvotes: 13