Solving “No managed connections available within configured blocking timeout” error

This article discusses how to solve the error “No managed connections available within configured blocking timeout” which happens when you are not able to collect a Connection object from a WildFly Datasource.

Here is an example of this error, which can be found in the application server logs:

Caused by: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/datasource/PostgreDS
    at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:390)
    at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:368)
    at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:464)
    at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:129)
    ... 51 more
Caused by: javax.resource.ResourceException: IJ000655: No managed connections available within configured blocking timeout (30000 [ms])
    at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:377)
    at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getTransactionNewConnection(AbstractPool.java:495)
    at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getConnection(AbstractPool.java:374)
    at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:329)

    The datasource connection pool has not been tuned (e.g. max-pool-size and blocking-timeout-millis) correctly for the maximum load on the application.
    The application is leaking connections because it is not closing them and thereby returning them to the pool.
    Threads with connections to the database are hanging and holding on to the connections or slow performance (e.g. due to CPU or memory usage issues) may delay (otherwise rapid) return of connections by worker threads and lead to pool exhaustion.

There can be several reasons why you are not able to collect a Datasource object:

1) Your application is is not properly closing connections so there is a Connection leak which needs to be identified in your applications.

Actions:

2) Your datasource might not be tuned for the required load.

Actions:

  • Configure an appropriate value for max-pool-size and blocking-timeout-millis. Again, check the article WildFly Connection Pool configuration to find how to monitor the Datasource to find out the optimal values for max-pool-size and blocking-timeout-millis.

3) Your Database connection or SQL Statements are the bottleneck. Verify which statements are taking most of the time using your vendor’s SQL statements.

For example, MySQL provides a number of built-in tools to check the long running transaction. First of all, SHOW PROCESSLIST or SHOW FULL PROCESSLIST commands can expose the running queries in real-time.