On 22/05/2023 09:45, Stefan López Romero wrote:
Hello,
I have the problem that the Tomcat connection pool uses more than the
maxActive connections. In my Dropwizard application I have configured a
maxSize of 30, but I found the following message in the logs.
Timeout: Pool empty. Unable to fetch a connection in 15 seconds, none
available[size:31; busy:31; idle:0; lastwait:15000]
This seems to be related to a high pressure on the DB. In the DB logs I
also found some connection issues
The code in the PooledConnection class does not seem to be completely
bulletproof, because there can't be only two threads that have gone
through the first if-two, or am I wrong?
Given that size is an AtomicInteger, I don't see a sequence of calls
from multiple threads that could result in more than maxActive
connections being created.
Also, it would have saved me some time if you had referenced the correct
class. The quoted code is part of ConnectionPool, not PooledConnection.
//if we get here, see if we need to create one
//this is not 100% accurate since it doesn't use a shared
//atomic variable - a connection can become idle while we are creating
//a new connection
if (size.get() < getPoolProperties().getMaxActive()) {
//atomic duplicate check
if (size.addAndGet(1) > getPoolProperties().getMaxActive()) {
//if we got here, two threads passed through the first if
size.decrementAndGet();
} else {
//create a connection, we're below the limit
return createConnection(now, con, username, password);
}
} //end if
In the end, this problem causes all my available DB connections to be
used up and my application to fail.
Is this a known problem? Is there a workaround?
At worst, this appears to be an off-by-one error either in the error
message or the connection counting logic. Even with that addressed, it
looks as if either the application has a connection leak or you need a
bigger connection pool to support the required load.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org