Skip to content

Dropwizard HealthCheck waits for connection timeout on shutdown pool #2325

Description

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

  1. Create a HikariCP pool with metrics and health check registry configured
  2. Shut down the pool using dataSource.close()
  3. Poll the registered ConnectivityHealthCheck
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions