Bug 54906 - WebappClassLoader.loadedByThisOrChild can throw ConcurrentModificationException
Summary: WebappClassLoader.loadedByThisOrChild can throw ConcurrentModificationException
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 8.0.x-trunk
Hardware: PC Linux
: P2 enhancement (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-29 19:25 UTC by Nate Clark
Modified: 2013-05-04 21:54 UTC (History)
0 users



Attachments
Patch to catch ConcurrentModificationException while iterating over a collection (1.91 KB, patch)
2013-04-29 19:25 UTC, Nate Clark
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nate Clark 2013-04-29 19:25:04 UTC
Created attachment 30240 [details]
Patch to catch ConcurrentModificationException while iterating over a collection

This is related to bug 54497. A common exception seen in 7.0.33 during stop is a ConcurrentModification in loadedByThisOrChild.

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to stop component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[/mobile/login/oauth]]
	at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:252)
	at java.util.concurrent.FutureTask.get(FutureTask.java:111)
	at org.apache.catalina.core.ContainerBase.stopInternal(ContainerBase.java:1179)
	at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
	at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1575)
	at org.apache.catalina.core.ContainerBase$StopChild.call(ContainerBase.java:1564)
	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
	at java.util.concurrent.FutureTask.run(FutureTask.java:166)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:722)
Caused by: org.apache.catalina.LifecycleException: Failed to stop component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[/mobile/login/oauth]]
	at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:236)
	... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to stop component [WebappLoader[/mobile/login/oauth]]
	at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:236)
	at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5521)
	at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
	... 7 more
Caused by: java.util.ConcurrentModificationException
	at java.util.Vector$Itr.checkForComodification(Vector.java:1156)
	at java.util.Vector$Itr.next(Vector.java:1133)
	at org.apache.catalina.loader.WebappClassLoader.loadedByThisOrChild(WebappClassLoader.java:2599)
	at org.apache.catalina.loader.WebappClassLoader.checkThreadLocalMapForLeaks(WebappClassLoader.java:2515)
	at org.apache.catalina.loader.WebappClassLoader.checkThreadLocalsForLeaks(WebappClassLoader.java:2455)
	at org.apache.catalina.loader.WebappClassLoader.clearReferences(WebappClassLoader.java:1996)
	at org.apache.catalina.loader.WebappClassLoader.stop(WebappClassLoader.java:1902)
	at org.apache.catalina.loader.WebappLoader.stopInternal(WebappLoader.java:661)
	at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
	... 9 more

The fix for 54497 stops the exception from failing the stop but it still fails the rest of the ThreadLocal leak check. It would be better if ConcurrentModificationException was caught in loadedByThisOrChild and only that one check fails.
Comment 1 Mark Thomas 2013-05-04 21:54:21 UTC
loadedByThisOrChild() is called by more than just the thread load code so I used your patch but with a dedicated error message rather than re-using an existing one.

The fix has been applied to trunk and 7.0.x and will be included in 7.0.40 onwards.