Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hikaricp maintaining the closed connections, the other threads in the application getting the Connection is closed issue #2282

Open
kannaiahuppulagithub opened this issue Jan 15, 2025 · 1 comment

Comments

@kannaiahuppulagithub
Copy link

In one of our application, we are suspecting the behavior of hikaricp maintaining the closed connections.

One connection is closed by the database server , the expectation is this connection must not maintained in the pool and must not be re used by the other threads, but we observed that the same connection is being used by the other threads.

We are using the MYSQL 8 database and Mariadb driver (mariadb-java-client-2.2.6) and HikariCP-5.0.1, we did not set the test query as jdbc4.0 is being used the test connection would be use isValid() method on connection object.

The application is developed using the Spring 5.3.32, hibernate 5.3.30.

I am going through the latest releases and commits from HIKARI CP , I found the following merge request , will it close the bug which i am reporting above?
merged #2157 close connections marked as evicted instead of returning them to the pool

@cdprete
Copy link

cdprete commented Jan 30, 2025

I can see the same from my side with tons of:

Exception in thread "pool-4-thread-6" org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [INSERT INTO prices(date_logical_session, market_code, currency_code, valor_number, value_type, statistic_type, val)
SELECT UNNEST(?) AS date_logical_session,
       UNNEST(?) AS market_code,
       UNNEST(?) AS currency_code,
       UNNEST(?) AS valor_number,
       UNNEST(?) AS value_type,
       UNNEST(?) AS statistic_type,
       UNNEST(?) AS val
RETURNING NOTHING
]; SQL state [null]; error code [0]; Connection is closed
        at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1557)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:677)
        at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:972)
        at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:1016)
        at com.foo.hiku.load.cockroachdb.CockroachDbRepository.lambda$save$2(CockroachDbRepository.java:85)
        at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:357)
        at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:230)
        at com.foo.hiku.load.cockroachdb.CockroachDbRepository.save(CockroachDbRepository.java:84)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:359)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:196)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:380)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:727)
        at com.foo.hiku.load.cockroachdb.CockroachDbRepository$$SpringCGLIB$$0.save(<generated>)
        at com.foo.hiku.load.cockroachdb.CockroachDbPersister.persist(CockroachDbPersister.java:73)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
        at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.sql.SQLException: Connection is closed
        at com.zaxxer.hikari.pool.ProxyConnection$ClosedConnection.lambda$getClosedConnection$0(ProxyConnection.java:503)
        at jdk.proxy3/jdk.proxy3.$Proxy63.prepareStatement(Unknown Source)
        at com.zaxxer.hikari.pool.ProxyConnection.prepareStatement(ProxyConnection.java:328)
        at com.zaxxer.hikari.pool.HikariProxyConnection.prepareStatement(HikariProxyConnection.java)
        at org.springframework.jdbc.core.JdbcTemplate$SimplePreparedStatementCreator.createPreparedStatement(JdbcTemplate.java:1719)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:656)
        ... 20 more

I'm using Spring Boot 3.4.2 where the Hikari dependency as well as the PostgreSQL JDBC driver one come from the Spring Boot BoM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants