You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by bu...@apache.org on 2011/03/03 00:54:25 UTC

DO NOT REPLY [Bug 50858] New: Classloader leak when using Log4j in a webapp container such as Tomcat, WebLogic

https://issues.apache.org/bugzilla/show_bug.cgi?id=50858

           Summary: Classloader leak when using Log4j in a webapp
                    container such as Tomcat, WebLogic
           Product: Log4j
           Version: unspecified
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Appender
        AssignedTo: log4j-dev@logging.apache.org
        ReportedBy: piepera@pragmatics.com


This is possibly redundant with bug #46221, however, different classes and
libraries appear to be involved, so I am submitting this anyways.

I have implemented a trivial "Hello World" Web Application, which invokes 
"LogManager.getLogger(HelloServlet.class)". Demonstrating the classloader leak
is a little cumbersome, I apologize, but here are the steps:
  1. Deploy the attached "simple.war" to the web container of your choice (I
used Tomcat v6.0.29)
  2. Navigate to http://localhost:8080/simple; you should see a "Hello, world!"
message. A warning will also be logged that log4j was not instantiated
properly.
  3. Undeploy "simple.war".
  4. Using jps/jmap/jhat, view the heap dump of your web container. View
references to the WebAppClassLoader, excluding weak references. You will see
that the WebAppClassLoader still has static references from about a dozen Log4j
classes, such as org.apache.log4j.Category and org.apache.log4j.Priority.ERROR.

I also implemented a ServletContextListener to call LogManager.shutDown() and
Introspector.flushCaches(), following advice from
http://marc.info/?l=log4j-user&m=109585865720819. This didn't solve the
problem. The only way I could resolve the ClassLoader leak was to remove all
references to LogManager.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 50858] Classloader leak when using Log4j in a webapp container such as Tomcat, WebLogic

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50858

Aaron Pieper <pi...@pragmatics.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |piepera@pragmatics.com

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 50858] Classloader leak when using Log4j in a webapp container such as Tomcat, WebLogic

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50858

--- Comment #3 from Aaron Pieper <pi...@pragmatics.com> 2011-03-02 19:00:22 EST ---
Created an attachment (id=26724)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=26724)
The html output from jhat, showing the rootset references from log4j to the
WebappClassLoader.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 50858] Classloader leak when using Log4j in a webapp container such as Tomcat, WebLogic

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50858

--- Comment #1 from Aaron Pieper <pi...@pragmatics.com> 2011-03-02 18:56:18 EST ---
Created an attachment (id=26722)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=26722)
A war file which demonstrates the ClassLoader leak

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 50858] Classloader leak when using Log4j in a webapp container such as Tomcat, WebLogic

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50858

--- Comment #4 from Stefan Franke <s....@bebbosoft.de> 2011-07-20 16:05:25 UTC ---
It seems that there is a ThreadLocal reference the WAR/EAR class loader, unload
will only occur, if the thread releases the thread local resources or dies:

--> java.lang.reflect.Method@0x31054290 (77 bytes) (field returnType:)
--> class com.sun.xml.bind.v2.schemagen.xmlschema.ComplexType (84 bytes) (??:)
--> org.apache.felix.framework.ModuleImpl$ModuleClassLoaderJava5@0x2ec33a28 (70
bytes) (field parent:)
--> java.net.URLClassLoader@0x2a206438 (62 bytes) (field classes:)
--> java.util.Vector@0x2a1ea138 (24 bytes) (field elementData:)
--> [Ljava.lang.Object;@0x304386c0 (1288 bytes) (Element 59 of
[Ljava.lang.Object;@0x304386c0:)
--> class org.apache.felix.framework.util.EventDispatcher (84 bytes) (static
field m_thread:)
--> java.lang.Thread@0x2a208840 (108 bytes) (field group:)
--> java.lang.ThreadGroup@0x2a16f8d8 (43 bytes) (field groups:)
--> [Ljava.lang.ThreadGroup;@0x2b2cc2d0 (40 bytes) (Element 2 of
[Ljava.lang.ThreadGroup;@0x2b2cc2d0:)
--> java.lang.ThreadGroup@0x2b326060 (43 bytes) (field threads:)
--> [Ljava.lang.Thread;@0x313d5b00 (136 bytes) (Element 5 of
[Ljava.lang.Thread;@0x313d5b00:)
--> com.sun.grizzly.http.HttpWorkerThread@0x31323718 (156 bytes) (field
threadLocals:)
--> java.lang.ThreadLocal$ThreadLocalMap@0x31332de0 (20 bytes) (field table:)
--> [Ljava.lang.ThreadLocal$ThreadLocalMap$Entry;@0x334e6c98 (16392 bytes)
(Element 2010 of [Ljava.lang.ThreadLocal$ThreadLocalMap$Entry;@0x334e6c98:)
--> java.lang.ThreadLocal$ThreadLocalMap$Entry@0x332826c0 (28 bytes) (field
value:)
--> com.sun.corba.ee.spi.orbutil.codegen.Wrapper$Environment@0x33283d10 (24
bytes) (field root:)
--> com.sun.corba.ee.impl.orbutil.codegen.ClassGeneratorImpl@0x33215020 (71
bytes) (field methods:)
--> java.util.ArrayList@0x33223a30 (20 bytes) (field elementData:)
--> [Ljava.lang.Object;@0x330e9480 (240 bytes) (Element 35 of
[Ljava.lang.Object;@0x330e9480:)
--> com.sun.corba.ee.impl.orbutil.codegen.MethodGenerator@0x3323cd20 (53 bytes)
(field rtype:)
--> com.sun.corba.ee.spi.orbutil.codegen.Type@0x33217db8 (49 bytes) (field
typeClass:)
--> class foo.bar.XYDTO (84 bytes) (??:)
--> org.glassfish.javaee.full.deployment.EarClassLoader@0x3295df18 (92 bytes)
(field classes:)

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 50858] Classloader leak when using Log4j in a webapp container such as Tomcat, WebLogic

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50858

--- Comment #2 from Aaron Pieper <pi...@pragmatics.com> 2011-03-02 18:57:43 EST ---
Created an attachment (id=26723)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=26723)
A project for building the sample war file, using maven.

This maven project includes a pom.xml, web.xml, and some java source files. You
should be able to build it with "mvn clean install".

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org