Bug 33743 - WebappClassLoader race condition
Summary: WebappClassLoader race condition
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 5.0.28
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2005-02-25 18:04 UTC by Matthias Ernst
Modified: 2005-12-07 11:12 UTC (History)
2 users (show)

standalone testcase (1.30 KB, text/plain)
2005-02-25 18:06 UTC, Matthias Ernst
Syncing when checking binaryContent==null (1.06 KB, patch)
2005-03-29 17:00 UTC, Remy Maucherat
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Ernst 2005-02-25 18:04:07 UTC
WebAppClassLoader may fail if concurrent threads try to load a not-yet-loaded class.

two threads enter loadClass(name, resolve) (line 1214) concurrently.
none of them finds a loaded class, so both enter findClass (827) and
findClassInternal (1559). 

Now one thread goes ahead, finds the resource and defines the class.
Consequently, it sets entry.binaryContent to null (1633). Thread 2 now
checks binaryContent for null (1572) and throws a ClassNotFoundException.

In the field, this error occurs, if you start Tomcat and load a number of
different jsps concurrently that all use the same tag class.

I also have a standalone testcase where I made WCL#addRepository(String,File)

As it seems, #loadClass(String, boolean) (1211) should be synchronized, as in
the superclasses.

Comment 1 Matthias Ernst 2005-02-25 18:06:33 UTC
Created attachment 14362 [details]
standalone testcase

Test produces output like the following:

class hox.util.Util

intermingled with

java.lang.ClassNotFoundException: hox.util.Util


	at org.apache.catalina.loader.test.WCT$1.run(WCT.java:35)
Comment 2 Remy Maucherat 2005-02-25 18:11:28 UTC
This will not be fixed for now.
Comment 3 Matthias Ernst 2005-02-28 13:27:28 UTC
Great. It leads to compiled JSP classes that do *not* recover by reloading. They
have a persistent "NoClassDefFoundError" attached.

Will you apply the fix in 5.5 ?
Comment 4 Remy Maucherat 2005-03-29 16:59:15 UTC
No, I will not apply your proposed fix. As it is, I cannot reproduce any problem
using the provided tester (so if I cannot do it using a microtest, it is even
less likely to occur in HTTP land). Maybe thread startup time is too slow on my
test machine.

I see that there's a flaw in the current syncing, however, and I am willing to
apply the attached patch which should resolve the problem.
Comment 5 Remy Maucherat 2005-03-29 17:00:18 UTC
Created attachment 14585 [details]
Syncing when checking binaryContent==null
Comment 6 Remy Maucherat 2005-04-05 11:57:31 UTC
My patch should address the possible race on entry.binaryContent.
Comment 7 quartz 2005-11-25 21:53:22 UTC
On which version is this fixed?
(kind of urgent for me to know...thanks!)
Comment 8 quartz 2005-12-07 16:23:52 UTC
Hi, the bug was reported on 5.0.28, 
I've seen it on 5.0.27 and 5.0.30.
A patch was made, but doesn't say which build is fixed.
Comment 9 Mark Thomas 2005-12-07 20:12:05 UTC
Fixed in 5.5.10 onwards.