Bug 56275 - Classloader leak in DirContextURLStreamHandler
Summary: Classloader leak in DirContextURLStreamHandler
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Catalina (show other bugs)
Version: unspecified
Hardware: All Mac OS X 10.4
: P2 normal (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-17 09:14 UTC by Nikita Salnikov-Tarnovski
Modified: 2014-03-23 09:36 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nikita Salnikov-Tarnovski 2014-03-17 09:14:26 UTC
I am a developer of the tool named Plumbr, which detects memory leaks in user applications. Quite a few of our clients got reports about WebappClassLoader being retained after application undeploy. Classloader is retained in "clBindings" static field of org.apache.naming.resources.DirContextURLStreamHandler class. This prevents application's class loader from being garbage collected and eventually leads to OutOfMemoryError: PermGen.

Unfortunately, I have no steps to reproduce the issue.
Comment 1 Mark Thomas 2014-03-19 21:42:14 UTC
Hmm. For this to happen an exception would have to be thrown during web application stop that prevented the code that de-registers the associated class loader from being called.

8.0.x is immune to this issue because the registration and deregistration code has been removed as part of the refactoring of resource handling.

I've been through the 7.0.x code and I can't see any obvious way to trigger this. All the obvious exceptions that could trigger the problem are caught, logged and not re-thrown. The only exceptions excluded from the process are fatal to the JVM anyway.


I do see a possible way to trigger this memory leak in 6.0.x but I need to do some testing to confirm it.
Comment 2 Mark Thomas 2014-03-19 22:02:20 UTC
Confirmed. A filter that throws an unchecked exception on destroy can trigger this. This issue has been fixed in 7.0.x. I'll look at putting together a proposal to back-port the changes to 6.0.x
Comment 3 Mark Thomas 2014-03-19 22:36:16 UTC
I've back-ported the fix and tested that it works. The fix has been proposed for 6.0.x.
Comment 4 Mark Thomas 2014-03-23 09:36:51 UTC
This has been fixed in 6.0.x and will be included in 6.0.40 onwards.