messaginghub / pooled-jms

A JMS Connection pool for messaging applications supporting JMS 1.1 and 2.0 and Jakarta JMS clients
Apache License 2.0
50 stars 24 forks source link

java.util.NoSuchElementException: Pool exhausted #15

Closed mafrankowski closed 4 years ago

mafrankowski commented 4 years ago

I've got following exception from pooled-jms code: java.util.NoSuchElementException: Pool exhausted at org.apache.commons.pool2.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:362) at org.apache.commons.pool2.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:265) at org.messaginghub.pooled.jms.JmsPoolConnectionFactory.createJmsPoolConnection(JmsPoolConnectionFactory.java:721) ... 109 common frames omitted

I'm using version 1.0.5 and have configured connectionIdleTimeout/connectionCheckInterval properties on my JmsPoolConnectionFactory. I suspect that wrong exception is caught in JmsPoolConnectionFactory.createJmsPoolConnection method in line 772.

tabish121 commented 4 years ago

Please provide a test case that can reproduce the issue

mafrankowski commented 4 years ago

It is a race condition as indicated in comment in JmsPoolConnectionFactory, but I was able to reproduce it with following test.

@Test
public void testCreateConnection() throws Exception {
    cf.setConnectionIdleTimeout(1);
    cf.setConnectionCheckInterval(1);
    for (int i = 0;i< 100000;++i){
        Connection connection = cf.createConnection();
        assertNotNull(connection);
        connection.close();
        Thread.sleep(1);
    }
}