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
# 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.
Check it now, free
- Open port checker: Is a TCP port open, closed or filtered from the internet?
Related reading
- Cloudflare error 522: connection timed out: Fix Cloudflare error 522 "Connection timed out": the origin did not complete the TCP connection in time. Overloaded servers, dropped packets and wrong DNS.
- Nginx "upstream timed out (110)": how to fix it: Fix Nginx upstream timed out (110: Connection timed out) while reading response header: find the slow request, tune proxy timeouts and fix the backend.
- Error: connect ETIMEDOUT: What ETIMEDOUT means, how it differs from ECONNREFUSED, the usual causes such as firewalls, security groups and wrong IPs, and how to set timeouts.
- SSH connection refused: how to fix it: Fix "ssh: connect to host port 22: Connection refused": sshd stopped, wrong port, firewalls and fail2ban, and how to get back in when you are locked out.
- ERR_CONNECTION_TIMED_OUT: why a site will not load: Why browsers show ERR_CONNECTION_TIMED_OUT, how to tell a client problem from a server one, and the firewall, DNS and server checks that find the cause.
- 504 Gateway Timeout: causes and fixes: What causes 504 Gateway Timeout errors, how timeouts stack across CDN, load balancer and Nginx, and how to find and fix the slow request.
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.