java
resource_error
ai_generated
true
Unable to acquire connection from pool. Connection pool exhausted
ID: java/connection-pool-exhausted
85%Fix Rate
90%Confidence
90Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 17 | active | — | — | — |
Root Cause
All connections in the database connection pool (HikariCP, DBCP, C3P0) are in use and the pool cannot allocate a new one. Usually caused by connection leaks (not closing connections), long-running queries, or an undersized pool.
genericWorkarounds
-
90% success Enable HikariCP leak detection to find unclosed connections
1. Set leakDetectionThreshold in HikariCP config (e.g., 30000 for 30 seconds). 2. Run the application under load — HikariCP will log stack traces of code that borrowed a connection and did not return it within the threshold. 3. Fix the leak by ensuring every connection/statement/resultset is closed in a try-with-resources block. 4. Verify the fix by monitoring active connection count.
-
88% success Ensure all database operations use try-with-resources to guarantee connection return
1. Audit all code that obtains a connection from the pool. 2. Wrap every Connection, PreparedStatement, and ResultSet in a try-with-resources block. 3. In Spring, use @Transactional or JdbcTemplate which handle connection management automatically. 4. After fixing leaks, right-size the pool to roughly 2x the number of concurrent request-handling threads.
Dead Ends
Common approaches that don't work:
-
Simply increasing the maximum pool size without investigating the root cause
70% fail
If connections are being leaked (not returned to the pool), increasing the pool size just delays the problem. The pool will exhaust again, now using more database resources. Databases also have their own connection limits.
-
Disabling connection pool timeout to wait indefinitely for a connection
85% fail
This converts a fast-failing error into threads that hang indefinitely, leading to thread pool exhaustion and complete application unresponsiveness. The user experience goes from an error message to a frozen application.
Error Chain
Leads to:
Preceded by:
Frequently confused with: