Bug 34703

Summary: Invalid synchronization in PageData leads to java.lang.IllegalThreadStateException
Product: Taglibs Reporter: Brett Randall <brett_s_r>
Component: Scrape TaglibAssignee: Tomcat Developers Mailing List <dev>
Severity: major    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Brett Randall 2005-05-02 13:18:00 UTC
A problem with thread synchronization in org.apache.taglibs.scrape.PageData
leads to a java.lang.IllegalThreadStateException.  Looking at PageData CVS rev 1.15.

In scrapePage(), a synchronized(scraping) attempts to protect the instantiation
and start()-ing of the new Page object (Thread).  This fails however, as
scraping is an instance variable, and whilst still inside the critical section,
scraping is reassigned:

scraping = new Boolean(true);

... unprotecting the critical section.  The result is that it is possible for
two threads to attempt to start() the same page object, resulting in:

	at java.lang.Thread.start(Native Method)
	at org.apache.taglibs.scrape.PageData.scrapePage(PageData.java:549)
	at org.apache.taglibs.scrape.PageTag.doEndTag(PageTag.java:152)
	at org.apache.jsp.scrap_jsp._jspService(scrap_jsp.java:165)
	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162)
	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)

Recommended solution: don't use "scraping" as the mutex if it needs to be
reassigned during the critical section.  A second lock Object might be more

As per any thread-related bug, this is difficult to reproduce, as you need two
threads to hit the expiring page at once, however in this case a review of the
code should make it clear how this problem can occur, and the fix is fairly simple.

Let me know if you need a patch submitted.
Comment 1 Henri Yandell 2009-11-29 19:42:07 UTC
Resolving. Taglib has been retired.