Home โบ Java exceptions โบ SQLTransientConnectionException
SQLTransientConnectionException: causes and fixes
HikariCP could not give out a connection within the timeout: the pool is exhausted or the database is unreachable.
What it looks like
java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30000msExtends SQLTransientException in java.sql.
What it means
Every request that needs the database borrows a connection from the pool. If all connections stay busy for longer than connectionTimeout (30 seconds by default) the borrower gives up with this exception. Either the pool is too small for the load, or connections are held too long (slow queries, transactions open during remote calls), or they are leaked and never returned. Newer HikariCP versions include the pool state in the message: total, active, idle and waiting.
Common causes
- Connection leaks: a connection obtained manually and never closed, or a transaction left open.
- Slow queries or long transactions holding connections.
- A pool size too small for the number of concurrent requests (or too many instances for the database limit).
- A database that is down, overloaded or rejecting connections.
How to fix it
- Turn on
leak-detection-thresholdto log the stack trace of code that holds a connection too long. - Shorten transactions and move remote calls outside them; disable open-in-view.
- Size the pool from measured load; see the HikariCP pool size calculator.
- Check database health and max_connections across all instances.
Broken and fixed
@Transactional
public void process() {
var data = repo.load();
httpClient.send(...); // connection held during the remote call
}public void process() {
var data = loader.load(); // short transaction
var result = httpClient.send(...); // no connection held
writer.save(result); // another short transaction
}๐ Unravel the failing code ๐ Unravel the fix
In Spring and enterprise code
If the pool shows active equal to total with many waiting, it is saturation or leaks; if active is low, the database is probably unreachable.
Debug it faster
Paste the whole stack trace into the stack trace beautifier to hide framework frames, jump to the root cause and find the first line of your own code. It runs in your browser, so the trace never leaves your machine.
Frequently asked questions
Is SQLTransientConnectionException a checked or unchecked exception?
SQLTransientConnectionException is a checked exception (it extends SQLTransientException), so the compiler forces you to catch it or declare it with throws.
Which package is SQLTransientConnectionException in?
It lives in java.sql, so the import is import java.sql.SQLTransientConnectionException;.
What is the first thing to check when I see SQLTransientConnectionException?
Read the message and the first stack trace line in your own code. The usual causes are: Connection leaks: a connection obtained manually and never closed, or a transaction left open; and Slow queries or long transactions holding connections.