Skip to content

Troubleshooting guide

HikariCP "Connection is not available": how to fix it

Every connection in the pool was in use and none came back within `connectionTimeout`. The pool is usually fine; connections are being held too long.

3 min read11 sectionsUpdated

On this page

Key points

  • The message reports total, active, idle and waiting.
  • Leak detection logs the stack trace that took the connection.
  • Bigger pools often make it worse.
  • Remote calls inside transactions hold connections needlessly.

What it means

A thread requested a connection and waited 30 seconds, the default. The error includes the state: total=10, active=10, idle=0, waiting=25. Active equal to total, with many waiting, means the pool is saturated.

Common causes

  • Slow queries keeping connections out.
  • A leak, where code does not close a connection.
  • HTTP or queue calls inside @Transactional.
  • Pool too small for the concurrency.
  • Nested transactions needing a second connection while holding the first.

Diagnose it

Turn on leak detection for a while, and read pool metrics.

bash
# application.properties
spring.datasource.hikari.leak-detection-threshold=20000
logging.level.com.zaxxer.hikari=DEBUG

# Spring Boot Actuator metrics
curl -s localhost:8080/actuator/metrics/hikaricp.connections.active
curl -s localhost:8080/actuator/metrics/hikaricp.connections.pending

# Thread dump: who is waiting, and who holds?
jstack PID | grep -B2 -A12 'HikariPool'

Fixes

Use try-with-resources for manual JDBC, and fix whichever path the leak report names. Remove remote calls from transactions. Tune the slow queries. Avoid REQUIRES_NEW under load, because it needs a second connection and can deadlock the pool. Set a sensible maximumPoolSize, and a maxLifetime shorter than the database or firewall limits. Avoid lowering connectionTimeout to hide the error: a shorter wait only makes requests fail sooner, without returning a single connection to the pool. It can be useful for failing fast, as long as you also fix what holds the connections.

How big should the pool be?

HikariCP's documentation points to a surprisingly small formula: connections = (core count x 2) + effective spindle count. A pool of 10 serves very many requests if queries are short. Think in terms of Little's law: required connections equal the request rate multiplied by the average time each holds one. With 200 requests per second and 10 ms each, you need two. If you need 100, then the hold time is the real problem. Across all instances, the sum of pool sizes must stay beneath the database's limit.

Catch it automatically

Chart pending connections and acquisition time: any sustained pending is a warning. APM shows the time spent waiting for a connection as a distinct part of the trace, separate from query time. See also the connection pool guide.

Frequently asked questions

Should I increase maximumPoolSize?

Only after checking for leaks and slow queries.

Is leak detection safe in production?

Yes, it has very low overhead.

What does connectionTimeout do?

It sets how long a thread waits for a connection from the pool.

Check it now, free

Watch your own site and services with VitalRix

Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.