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