When a HikariCP pool is shut down, CodahaleHealthChecker.ConnectivityHealthCheck continues to wait for the full connection timeout duration on each health check poll, despite the pool being unable to provide connections.
Expected Behaviour
Health checks on a shut down pool should fail immediately without waiting for the connection timeout.
Actual Behaviour
Each health check takes approximately 5 seconds (the configured connection timeout) even though the pool is closed and will never return a connection.
Environment
- HikariCP Version: 6.3.0
- Java Version: 21
- Database: H2 (in-memory)
Reproduction Steps
- Create a HikariCP pool with metrics and health check registry configured
- Shut down the pool using
dataSource.close()
- Poll the registered
ConnectivityHealthCheck
- Observe that each health check takes the full connection timeout duration
Can be reproduced with the following code:
public static void main(String[] args) throws InterruptedException {
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:h2:mem:testdb");
config.setUsername("sa");
config.setPassword("");
config.setConnectionTimeout(5000);
config.setMetricRegistry(new MetricRegistry());
config.setHealthCheckRegistry(new HealthCheckRegistry());
HikariDataSource dataSource = new HikariDataSource(config);
HealthCheckRegistry healthCheckRegistry = (HealthCheckRegistry) config.getHealthCheckRegistry();
String healthCheckName = healthCheckRegistry.getNames().iterator().next();
dataSource.close();
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(() -> {
long startTime = System.currentTimeMillis();
healthCheckRegistry.runHealthCheck(healthCheckName);
long duration = System.currentTimeMillis() - startTime;
System.out.printf("Health check took %d ms%n", duration);
}, 0, 1, TimeUnit.SECONDS);
Thread.sleep(10000);
scheduler.shutdown();
}
which outputs:
Health check took 5021 ms
Health check took 5006 ms
When a HikariCP pool is shut down,
CodahaleHealthChecker.ConnectivityHealthCheckcontinues to wait for the full connection timeout duration on each health check poll, despite the pool being unable to provide connections.Expected Behaviour
Health checks on a shut down pool should fail immediately without waiting for the connection timeout.
Actual Behaviour
Each health check takes approximately 5 seconds (the configured connection timeout) even though the pool is closed and will never return a connection.
Environment
Reproduction Steps
dataSource.close()ConnectivityHealthCheckCan be reproduced with the following code:
which outputs: