Details
Description
DefaultMessageListenerContainer does not reliably manage its activeInvokerCount, which may prevent it from shutting down. Instead, it will wait indefinitely in
[email protected], prio=5, in group 'main', status: 'WAIT' at java.lang.Object.wait(Object.java:-1) at java.lang.Object.wait(Object.java:485) at org.springframework.jms.listener.DefaultMessageListenerContainer.doShutdown(DefaultMessageListenerContainer.java:489) at org.springframework.jms.listener.AbstractJmsListeningContainer.shutdown(AbstractJmsListeningContainer.java:211) at org.springframework.jms.listener.AbstractJmsListeningContainer.destroy(AbstractJmsListeningContainer.java:149)
In org.springframework.jms.listener.DefaultMessageListenerContainer.AsyncMessageListenerInvoker#run, #decreateActiveInvokerCount will never be called, if an exception is thrown from within the catch(Throwable ex) block, lines 886-908.
In the case at hand, a NPE is caused by https://jira.springframework.org/browse/SPR-5470, which has been fixed in 3.0, but not in 2.5.x. Other runtime exceptions are imaginable as well. This issue is fairly reproducible with an embedded ActiveMQ broker which is shut down at the same time as the listener (may cause JMSExceptions in the listener).
To fix this issue, I suggest to use a finally block in order to decrement the active invoker count, and perform other clean up as necessary.