Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConcurrentModificationException in SingleConnectionFactory$AggregatedExceptionListener [SPR-13421] #18000

spring-projects-issues opened this issue Sep 2, 2015 · 1 comment
in: messaging status: backported type: bug


Copy link

@spring-projects-issues spring-projects-issues commented Sep 2, 2015

Mike Noordermeer opened SPR-13421 and commented

The SingleConnectionFactory$AggregatedExceptionListener objects contains a list of delegates in a LinkedHashSet, protected by the SingleConnectionFactory.connectionMonitor lock object.

If you configure a SingleConnectionFactory with reconnectOnException = true, and use it in a SimpleMessageListenerContainer, the following will happen on a JMSException:

  1. SingleConnectionFactory$AggregatedExceptionListener.onException() is called, and starts looping over the delegates Set
  2. At a certain point in time, it will call SimpleMessageListenerContainer.onException(), which calls refreshSharedConnection(), createSharedConnection(), prepareSharedConnection(), connection.setExceptionListener()
  3. This modifies the delegates list (from the same thread, so the locking does not help)
  4. A ConcurrentModificationException will be thrown in SingleConnectionFactory$AggregatedExceptionListener.onException()

Full exception message:

Exception in thread "ActiveMQ Connection Executor: tcp://localhost/" java.util.ConcurrentModificationException
	at java.util.LinkedHashMap$LinkedHashIterator.nextNode(
	at java.util.LinkedHashMap$
	at org.springframework.jms.connection.SingleConnectionFactory$AggregatedExceptionListener.onException(
	at org.apache.activemq.ActiveMQConnection$
	at java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.util.concurrent.ThreadPoolExecutor$

The list of delegates should probably be copied before iteration, or the SimpleMessageListenerContainer should not re-add itself as listener.

Affects: 4.1.7, 4.2.1

Issue Links:

  • #15030 Memory leak with SimpleMessageListenerContainer and ChainedExceptionListener on Single/CachingConnectionFactory
  • #20294 JMS Integration with Tibco causes deadlock while using DefaultMessageListenerContainer

Referenced from: commits f562eb5, 1ed1167

Backported to: 4.1.8

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 2, 2015

Juergen Hoeller commented

Good catch! Fixed for 4.2.2 now, and to be backported to 4.1.8.

Feel free to give the upcoming 4.2.2.BUILD-SNAPSHOT an early try...


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: messaging status: backported type: bug
None yet

No branches or pull requests

2 participants