Quick revision
The short answer
The message means every connection in the pool stayed busy for the full 30 seconds a caller was willing to wait. The usual causes are connections held too long (slow queries, long transactions, or remote calls made inside a transaction), connection leaks where code never closes a connection, a pool too small for the real concurrency, including more virtual threads than the pool can serve, and Open Session in View holding a connection for the whole request. We confirm each with HikariCP's active, idle and pending metrics, leakDetectionThreshold, thread dumps and the database's own session view.
What to remember
In this answer, we saw that the HikariCP timeout means all connections stayed borrowed for the whole connectionTimeout. The likely causes are connections held too long by slow queries, long transactions or remote calls inside transactions, leaks from code that never closes connections, a pool too small for the real concurrency, especially with virtual threads, and Open Session in View holding connections for the whole request. We confirm each with pool metrics, leakDetectionThreshold, thread dumps and pg_stat_activity, and resize only after the evidence says demand is real.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The message means every connection in the pool stayed busy for the full 30 seconds a caller was willing to wait. The usual causes are connections held too long (slow queries, long transactions, or remote calls made inside a transaction), connection leaks where code never closes a connection, a pool too small for the real concurrency, including more virtual threads than the pool can serve, and Open Session in View holding a connection for the whole request. We confirm each with HikariCP's active, idle and pending metrics, leakDetectionThreshold, thread dumps and the database's own session view.
Why this question is asked
This is probably the most common database error in Spring Boot services under load, and the tempting fix, a bigger pool, is often wrong because it hides the cause and pushes the queue into the database. Interviewers ask it to see whether we can reason from the symptom to the possible causes and confirm one with evidence. In this answer, we will read what the message really means, then go through each likely cause and how to confirm it, and end with how the pieces fit into a diagnosis plan.
1What the Message Really Says
HikariCP lends connections from a pool of maximumPoolSize connections, 10 by default. When a thread asks for one and none is free, it waits up to connectionTimeout, 30,000 ms by default. The message HikariPool-1 - Connection is not available, request timed out after 30000ms means that for 30 seconds, every connection was borrowed and none came back in time for this caller.
So the problem is about the rate at which connections are returned. A pool of 10 connections can serve 10 operations at once; if each holds a connection for 20 ms, that is 500 operations per second. If each holds it for 2 seconds, it is 5 per second, and anything above that queues. Every cause below either makes connections stay out longer, removes them from circulation, or brings more demand than the pool can serve. The log message from HikariCP also usually includes the pool's state, such as total=10, active=10, idle=0, waiting=37, which is the first clue.
2Cause 1: Connections Held Too Long
A connection is held from the first database access in a transaction until commit, or for each statement outside one. Slow queries hold it longer: a missing index that turns a 5 ms lookup into a 3-second scan cuts pool throughput by a factor of 600. Long transactions hold it too, for example a @Transactional method that processes a large file. The most damaging pattern is a remote call inside a transaction.
Notice that the connection does nothing during the payment call, yet nobody else can use it. If the payment provider slows from 200 ms to 5 seconds, our pool runs dry even though the database is idle. To confirm it, we look at HikariCP's hikaricp.connections.usage metric, which shows how long connections are held, at slow query logs or pg_stat_statements on the database, and at pg_stat_activity for sessions in the state idle in transaction, which is the signature of a connection held while the application does something else. The fix is to keep remote calls outside the transaction and keep transactions short.
3Cause 2: Connection Leaks
A leak is a connection that is borrowed and never returned, usually from plain JDBC code that misses a close() on some error path, or a stream from queryForStream that is never closed. Each leak permanently removes one connection; after ten, the pool is empty and every caller times out until the service restarts. The pattern in metrics is distinctive: active connections climb step by step over hours and never fall, even at night.
HikariCP can find the culprit. With leakDetectionThreshold set, for example to 20 seconds (the minimum is 2 seconds), it logs a warning with the stack trace of the code that borrowed any connection held longer than that.
A warning can also fire for a connection that is merely held for a long time, so we read the stack trace and check whether the connection is eventually returned; HikariCP logs a follow-up message if it is. The fix is try-with-resources or letting JdbcTemplate manage the connection.
4Cause 3: A Pool Too Small for the Real Concurrency
Sometimes nothing is wrong except arithmetic. If a service handles 400 requests per second and each holds a connection for 50 ms, it needs about 20 connections on average, by Little's law (concurrency equals arrival rate times time held), and more for bursts; a pool of 10 cannot keep up. Metrics show active at the maximum and pending above zero during peaks, with normal query times.
Virtual threads make this more likely. With spring.threads.virtual.enabled=true, Tomcat no longer limits concurrency to 200 platform threads, so a traffic spike can create thousands of concurrent requests, all queuing on the same 10 connections. The pool becomes the real concurrency limit, which is fine if it is intended, but connectionTimeout should then be short and the requests should fail fast or be limited before reaching the pool. Raising the pool is valid when the database has headroom, within the total connection budget of all instances.
5Cause 4: Open Session in View
Spring Boot enables Open Session in View (OSIV) by default for JPA applications, spring.jpa.open-in-view=true, and logs a warning about it at startup. With OSIV, the persistence context stays open for the whole web request, so lazy associations can load while the view or JSON serialiser runs. The side effect is that once a request touches the database, it can keep its connection until the response is fully written, including time spent in remote calls, template rendering or slow clients.
To confirm it, we check the property and compare connection usage time with the time spent in repository calls. Setting spring.jpa.open-in-view=false returns connections at the end of each transaction; any LazyInitializationException that appears afterwards shows code that should fetch what it needs inside the service layer, for example with a fetch join or an entity graph.
6Confirming the Cause
We combine three views. The pool's metrics through Actuator and Micrometer show active, idle and pending connections and acquire and usage times over time; a step pattern means leaks, a spike pattern with long usage means slow work, and steady saturation with short usage means a small pool. A thread dump during the incident shows what the threads holding connections are doing: waiting in an HTTP client means remote calls in transactions; waiting in a socket read from the driver means slow queries. The database's own view, pg_stat_activity on PostgreSQL, shows each session's state and current query, so we can see active slow queries, idle in transaction sessions and their ages.
- Active grows in steps and never falls?watch
hikaricp.connections.activeover hoursYesLeak: enable leakDetectionThresholdNoNext check - Database sessions idle in transaction?pg_stat_activity during the incidentYesRemote calls or work inside transactionsNoNext check
- Queries slow on the database?slow log, pg_stat_statementsYesFix queries and indexesNoNext check
- OSIV on and usage time much longer than queries?
spring.jpa.open-in-viewYesTurn OSIV off, fetch in the serviceNoNext check - Real demand: resize within the database budgetpool saturated with short usage times; also limit concurrency
5 steps in order. Play them, or step through them one at a time.
Each branch has its own evidence; resizing is the last step, not the first.
7Follow-up questions
What does a REQUIRES_NEW call inside a transaction do to pool demand?
Propagation.REQUIRES_NEW suspends the current transaction and starts a new one, which needs a second connection, while the first stays borrowed and idle until the inner call finishes. So each such request needs two connections at once, doubling its demand. Under load this can even deadlock the pool: if all 10 connections are held by outer transactions waiting for an inner REQUIRES_NEW connection, no request can proceed until timeouts fire. We keep REQUIRES_NEW for short, rare operations such as audit records, or move that work out of the outer transaction.
Is lowering connectionTimeout a fix?
It does not fix the cause, but it improves the failure mode. With 30 seconds, waiting threads pile up and the service may stop responding entirely; with 2 or 3 seconds, excess requests fail fast, and the service recovers as soon as the cause clears. We lower it together with fixing the real problem.
Why not just set the pool size to 100?
If the database is the bottleneck, more connections make each query slower and the queue simply moves into the database. Across many instances, it can also exceed the database's max_connections. And if the cause is a leak or a remote call inside a transaction, a bigger pool only delays the same outage. We raise the pool only after confirming that demand is real and the database has capacity.
8Conclusion
In this answer, we saw that the HikariCP timeout means all connections stayed borrowed for the whole connectionTimeout. The likely causes are connections held too long by slow queries, long transactions or remote calls inside transactions, leaks from code that never closes connections, a pool too small for the real concurrency, especially with virtual threads, and Open Session in View holding connections for the whole request. We confirm each with pool metrics, leakDetectionThreshold, thread dumps and pg_stat_activity, and resize only after the evidence says demand is real.
Open with
The message means all ten connections were borrowed for the full thirty seconds a caller waited, so connections are not coming back fast enough. I would think of four causes.
Then, if they want more
First, connections held too long: slow queries, long transactions, or worst, remote calls inside a transaction, like calling a payment API inside a @Transactional method, where the connection sits idle but held; on the database I would see sessions idle in transaction.
Second, leaks, code that borrows a connection and never closes it, which shows as active connections climbing in steps and never dropping; I would turn on leakDetectionThreshold, which logs the stack trace of whoever borrowed a connection and held it too long. Third, the pool is simply too small for the concurrency.
Little's law tells me how many connections I need, rate times hold time, and with virtual threads enabled there is no longer a thread pool limiting concurrency, so thousands of requests can queue on ten connections.
Fourth, Open Session in View, which is on by default in Spring Boot with JPA and can keep the connection for the whole request including rendering. To confirm, I would use the HikariCP metrics through Actuator, active, idle, pending and usage time, a thread dump to see what the connection-holding threads are doing, and pg_stat_activity on the database.
And on the follow-up: a REQUIRES_NEW inside a transaction needs a second connection while holding the first, doubling demand and potentially deadlocking the pool.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- java.sql, package documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Your service logs 'HikariPool-1 - Connection is not available, request timed out after...": https://scrivio-interview-library.netlify.app/databases/jdbc/fafbcba2fc/