#7201 improve efforts to call listeners only when needed and guard against potential concurrent closures

Signed-off-by: Ludovic Orban <lorban@bitronix.be>
This commit is contained in:
Ludovic Orban 2022-01-17 10:20:48 +01:00
parent fdeb03d556
commit 25306366d4
1 changed files with 22 additions and 6 deletions

View File

@ -459,13 +459,29 @@ public abstract class AbstractConnectionPool extends ContainerLifeCycle implemen
@Override
public void close()
{
// Manually release and remove entries to do our best effort calling the listeners.
for (Pool<Connection>.Entry entry : pool.values())
// Forcibly release and remove entries to do our best effort calling the listeners.
try
{
if (entry.release())
released(entry.getPooled());
if (entry.remove())
removed(entry.getPooled());
for (Pool<Connection>.Entry entry : pool.values())
{
while (entry.isInUse())
{
if (entry.release())
{
released(entry.getPooled());
break;
}
}
if (entry.remove())
removed(entry.getPooled());
}
}
catch (Throwable x)
{
if (LOG.isDebugEnabled())
LOG.debug("Detected concurrent modification while forcibly releasing the pooled connections", x);
// We could not call the listeners for all entries, but at least the following
// pool.close() call will still release all resources.
}
pool.close();
}