how does Hikari recycle connections?

Gaël Oberson picture Gaël Oberson · Nov 15, 2015 · Viewed 8.3k times · Source

I please you all for an answer I could not find in the HikariCP doc. Given I set the following pool parameters:

minimumIdle 1
idleTimeout 10 minutes
maxLifeTime 20 minutes

When my app stays idle (with nobody making requests) during the night, I expect Hikari to close each connection 10 minutes after the connection's last request, after the last connection being closed create a new one (and hold it in the pool), and then close and re-create this idle connection every 20 minutes. Did I understood correctly?

The fact is that after an idle period on my app, I see (uppon the next request) the following exception:

WARN  c.z.hikari.proxy.ConnectionProxy - Connection oracle.jdbc.driver.T4CConnection@3c63f80e <POOL_NAME> marked as broken because of SQLSTATE(08003), ErrorCode(17008).
java.sql.SQLRecoverableException: Closed Connection

The connection has probably been closed by Oracle and cannot be used. I'll try to avoid this using the above config. Another point is that I do not understand why I get a closed connection from the pool. This should never happen, as Hikari does test the connection's state before returning it...

Note: I am not the owner of the DB, I cannot configure it or let it be reconfigured to suit my needs. I also have no access to its config.

Our set-up is Spring 4.1.6, Hibernate 4.3.7 with JPA 2.1 API, Hikari 2.1.0

Answer

brettw picture brettw · Nov 17, 2015

Your understanding of the pool parameters is correct. It is possible that the Oracle instance has a shorter idle timeout than 10 minutes. One thing you can do is to enable DEBUG level logging for the com.zaxxer.hikari package. You'll get a lot more information about what is going on internally within HikariCP, without being too noisy.

Feel free to post the log as an issue on Github and we'll take a look at it.