Skip to content

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

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

Closed
spring-projects-issues opened this issue Sep 2, 2015 · 1 comment
Assignees
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

Comments

@spring-projects-issues
Copy link
Collaborator

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/127.0.0.1:61616@52892" java.util.ConcurrentModificationException
	at java.util.LinkedHashMap$LinkedHashIterator.nextNode(LinkedHashMap.java:711)
	at java.util.LinkedHashMap$LinkedKeyIterator.next(LinkedHashMap.java:734)
	at org.springframework.jms.connection.SingleConnectionFactory$AggregatedExceptionListener.onException(SingleConnectionFactory.java:670)
	at org.apache.activemq.ActiveMQConnection$5.run(ActiveMQConnection.java:2004)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

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:

Referenced from: commits f562eb5, 1ed1167

Backported to: 4.1.8

@spring-projects-issues
Copy link
Collaborator Author

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...

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants