Skip to content
Advertisement

Hikari CP DB connection not release in Async block

I am using Spring Boot application which has API controller to generate reports . The actual service function is wrapped around @Async annotation and function makes DB calls and generates the csv reports . I am also using Hikari CP for connection pool management and JPA + QueryDSL for forming select queries .

I am seeing strange issue in that DB connections are not being released after the files are successfully generated. Every new call to the controller/service function creates new active connections and it remains active . Its not getting released because of which I am getting Connection is not available error from Hikari once my max pool size limit is reached.

Any suggestions why connection is not being released . The service function issues only select queries , no updates or inserts.

Hikari CP configs:

spring.datasource.hikari.maximum-pool-size: "80"
spring.datasource.hikari.idle-timeout: "300000"
spring.datasource.hikari.connectionTimeout: "600000"
spring.datasource.hikari.minimum-idle: "15"

My service function

@Async
@Override
public void exportListing(String[] filter) {
        try {
}
catch(Exception e)
{
}

Advertisement

Answer

I fixed it by wrapping it within @Transactional block which ensures that DB connections are closed once the function completes.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement