Bugzilla will be upgraded to version 5.0. The upgrade date is tentatively scheduled for 2 December 2018, pending final testing and feedback.
Bug 1017673 - ConcurrentModificationException in TimerService.getTimers()
ConcurrentModificationException in TimerService.getTimers()
Status: CLOSED CURRENTRELEASE
Product: JBoss Enterprise Application Platform 6
Classification: JBoss
Component: EJB (Show other bugs)
6.2.0
Unspecified Unspecified
unspecified Severity medium
: DR0
: EAP 6.3.0
Assigned To: Jan Martiska
Jan Martiska
Russell Dickenson
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-10-10 06:20 EDT by Jan Martiska
Modified: 2014-06-28 11:44 EDT (History)
4 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
If a bean attempted to create a new timer at the same time as another thread was calling the `getTimers()` method, a `ConcurrentModificationException` was thrown. This occurred because the `getTimers()` method did not call `synchronized()` on the timers. This issue is fixed in this release, and the timer service implementation's `getTimers()` method now properly calls `synchronized()` on the timers.
Story Points: ---
Clone Of:
Environment:
Last Closed: 2014-06-28 11:44:52 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
reproducer (3.03 KB, application/zip)
2013-10-10 06:20 EDT, Jan Martiska
no flags Details

  None (edit)
Description Jan Martiska 2013-10-10 06:20:46 EDT
Created attachment 810437 [details]
reproducer

The implementation of org.jboss.as.ejb3.timerservice.TimerService.getTimers() iterates over three collections (activePersistentTimers, persistentWaitingOnTxCompletionTimers, nonPersistentTimers) using a for-each loop without synchronizing on them.
This can lead to a ConcurrentModificationException if a bean is creating a timer and at the same time another thread is calling getTimers().

Reproducer mimicking this scenario is attached. Just deploy it to a running EAP instance. A Singleton bean will create/remove lots of timers and at the same time another thread will call getTimers repeatedly.

Expected outcome: it deploys successfully and says "No ConcurrentModificationException encountered"

Actual outcome - after some time: 
java.util.ConcurrentModificationException
	at java.util.HashMap$HashIterator.nextEntry(HashMap.java:894) [rt.jar:1.7.0_25]
	at java.util.HashMap$ValueIterator.next(HashMap.java:922) [rt.jar:1.7.0_25]
	at org.jboss.as.ejb3.timerservice.TimerServiceImpl.getTimers(TimerServiceImpl.java:372)
	at TimerGenerator.getTimers(TimerGenerator.java:63)	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_25]
(....)
Comment 2 Dimitris Andreadis 2013-10-24 14:28:05 EDT
Assigning jpai@redhat.com EJB issues to david.lloyd@redhat.com. Please re-assign to Cheng or others as needed.
Comment 3 Jan Martiska 2013-10-30 09:18:15 EDT
Going to fix this myself.
Comment 4 Jan Martiska 2013-11-06 05:29:22 EST
Can't reproduce on upstream, it seems it was fixed there earlier with commit 7a4541f6.
Comment 8 David M. Lloyd 2014-01-02 10:08:56 EST
The pull request looks OK so I'm devel_ack+ this.
Comment 9 Jan Martiska 2014-02-12 05:23:40 EST
Fixed in 6.3.0.DR0.

Note You need to log in before you can comment on or make changes to this bug.