Bug 1017673 - ConcurrentModificationException in TimerService.getTimers()
Summary: ConcurrentModificationException in TimerService.getTimers()
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: JBoss Enterprise Application Platform 6
Classification: JBoss
Component: EJB
Version: 6.2.0
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: DR0
: EAP 6.3.0
Assignee: Jan Martiska
QA Contact: Jan Martiska
Russell Dickenson
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-10-10 10:20 UTC by Jan Martiska
Modified: 2014-06-28 15:44 UTC (History)
4 users (show)

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.
Clone Of:
Environment:
Last Closed: 2014-06-28 15:44:52 UTC
Type: Bug
Embargoed:


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

Description Jan Martiska 2013-10-10 10:20:46 UTC
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 18:28:05 UTC
Assigning jpai EJB issues to david.lloyd. Please re-assign to Cheng or others as needed.

Comment 3 Jan Martiska 2013-10-30 13:18:15 UTC
Going to fix this myself.

Comment 4 Jan Martiska 2013-11-06 10:29:22 UTC
Can't reproduce on upstream, it seems it was fixed there earlier with commit 7a4541f6.

Comment 8 David M. Lloyd 2014-01-02 15:08:56 UTC
The pull request looks OK so I'm devel_ack+ this.

Comment 9 Jan Martiska 2014-02-12 10:23:40 UTC
Fixed in 6.3.0.DR0.


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