Bug 56857 - Thread safety issue in ApplicationContextFacade.invokeMethod
Summary: Thread safety issue in ApplicationContextFacade.invokeMethod
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 7.0.52
Hardware: PC Linux
: P2 major (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-14 21:42 UTC by Volker Kleinschmidt
Modified: 2014-09-03 11:06 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Kleinschmidt 2014-08-14 21:42:28 UTC
Multiple subsequent Thread dumps were exhibiting lots of threads hanging in HashMap.get() while in RUNNABLE status, and consuming high CPU - a typical indicator of a thread safety issue with these non-threadsafe Maps.
Thread stacks all as below.

ApplicationContextFacade implements ServletContext, these objects are singletons per webapp, and get passed around among multiple threads. Their private member "objectCache" is a HashMap, i.e. not thread safe, but gets accessed AND modified without any synchronization in invokeMethod().

Suggested remedy: change to a ConcurrentHashMap, which is thread-safe, and performs much better than synchronizing on every access.

"connector-93: userId=_101_1, sessionId=C9EC1C59DD2244557BC6231A5476000E" daemon prio=10 tid=0x00007fb1e40cf800 nid=0x7b90 runnable [0x00007fb1e82c3000]
   java.lang.Thread.State: RUNNABLE
	at java.util.HashMap.get(HashMap.java:326)
	at org.apache.catalina.core.ApplicationContextFacade.invokeMethod(ApplicationContextFacade.java:789)
	at org.apache.catalina.core.ApplicationContextFacade.doPrivileged(ApplicationContextFacade.java:767)
	at org.apache.catalina.core.ApplicationContextFacade.getContextPath(ApplicationContextFacade.java:428)
	at blackboard.portal.servlet.ModuleCustomizationServlet.service(ModuleCustomizationServlet.java:88)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
...
Comment 1 Volker Kleinschmidt 2014-08-14 21:44:04 UTC
As is common with thread safety issues, I have no strict replication steps. Issue occurs sporadically, however this particular method call (getContextPath) seems to trigger it fairly often.
Comment 2 Mark Thomas 2014-08-15 12:54:46 UTC
Fixed in 8.0.x for 8.0.11 onwards.
Comment 3 Volker Kleinschmidt 2014-09-02 18:45:04 UTC
Thanks for the quick follow-up. Any chance this could get backported to 7.x?
Comment 4 Violeta Georgieva 2014-09-03 10:45:27 UTC
The fix is downported in 7.0.x for 7.0.56 onwards.
Comment 5 Volker Kleinschmidt 2014-09-03 11:06:32 UTC
Great news, thank you.