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

Setting JmsPoolConnectionFactory.setConnectionCheckInterval causes active connections to be evicted #31

Closed meverden closed 1 year ago

meverden commented 1 year ago

The logic within org.apache.commons.pool2.impl.GenericKeyedObjectPool.evict() gives the EvictionPolicy higher precedence than KeyedPooledObjectFactory.validateObject().

This means the comment in org.messaginghub.pooled.jms.JmsPoolConnectionFactory.initConnectionsPool() is not true

// We always want our validate method to control when idle objects are evicted.
this.connectionsPool.setTestOnBorrow(true);
this.connectionsPool.setTestWhileIdle(true);

Since JmsPoolConnectionFactory leaves all pooled connections with a state of PooledObjectState.IDLE, they will be evicted after BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_DURATION, 30 minutes by default.

This causes code that is using an active connection to stacktrace, example:

javax.jms.IllegalStateException: The Session is closed
    at org.apache.activemq.ActiveMQSession.checkClosed(ActiveMQSession.java:772) ~[activemq-client-5.16.5.jar:5.16.5]
    at org.apache.activemq.ActiveMQSession.rollback(ActiveMQSession.java:597) ~[activemq-client-5.16.5.jar:5.16.5]
    at org.messaginghub.pooled.jms.JmsPoolSession.close(JmsPoolSession.java:112) ~[pooled-jms-1.2.4.jar:na]
moarychan commented 1 year ago

Is there a plan to release this fix for versions 1.x and 2.x ?

tabish121 commented 1 year ago

My suggestion would be to move to a Jakarta JMS 3 based client so you can use the 3.x release of pooled-jms