CachingConnectionFactory should catch exceptions on logical close [SPR-12148] #16762
Labels
in: messaging
Issues in messaging modules (jms, messaging)
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Milestone
Gordon Daugherty opened SPR-12148 and commented
When an application uses a CachingConnectionFactory it will encounter the issue shown in this stack trace if the underlying connection is killed AND the client tries to use the JMS Session object:
Caused by: javax.jms.IllegalStateException: Session is closed
at com.tibco.tibjms.TibjmsxSessionImp.getTransacted(TibjmsxSessionImp.java:4837)
at org.springframework.jms.connection.CachingConnectionFactory$CachedSessionInvocationHandler.logicalClose(CachingConnectionFactory.java:398)
at org.springframework.jms.connection.CachingConnectionFactory$CachedSessionInvocationHandler.invoke(CachingConnectionFactory.java:298)
at $Proxy30.close(Unknown Source)
at com.mycorp.client.core.ServiceProxyImpl.handleDisconnect(ServiceProxyImpl.java:226)
at com.mycorp.client.core.ServiceProxyImpl.sendRequest(ServiceProxyImpl.java:180)
... 29 more
One of my teammates was able to reproduce this by killing the Connection at the broker (Tibco v8) after exercising the software so that the cache contained some sessions.
We're using "reconnectOnException=true" (the default for CachingConnectionFactory).
I don't see any code in the CachingConnectionFactory that would catch exceptions thrown by javax.jms.Session.getTransacted(). It seems that the client should be able to successfully return a bad proxied session to the pool by calling ProxiedSession.close() and the pool should not ever hand that session out again.
Maybe I don't properly understand the responsibilities assigned to the code that's using the CachingConnectionFactory but I don't see a good way to handle this scenario from the client code's perspective. You don't want multiple threads discovering that they're holding a bad session and each one calling resetConnection() since they'd step on each other.
The code that throws the exception shown in the stack trace above appears to exist in all spring-jms versions after v2.5.5.
The code in question was introduced as part of this enhancement: #9706
Affects: 3.2.10, 4.1 RC2
Issue Links:
Referenced from: commits 82f8b43, 4255774, 8543a55
Backported to: 4.0.7, 3.2.11
The text was updated successfully, but these errors were encountered: