You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2008/11/17 13:17:40 UTC

DO NOT REPLY [Bug 46221] New: Leak WebappClassLoader with commons-logging and log4j

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

           Summary: Leak WebappClassLoader with commons-logging and log4j
           Product: Tomcat 5
           Version: 5.5.27
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Unknown
        AssignedTo: dev@tomcat.apache.org
        ReportedBy: debossoreille@idm.fr


Tomcat is leaking a few references to the WebappClassLoader instance when the
application is stopped and contains commons-logging and log4j packages.

The attached zip file is a very simple test case. I use Yourkit Java Profiler
to find the remaining references.

The leak is due to loggers not released by the various containers that are
alive until all the webapp is completely unloaded which does happen in my case
(start,stop,start,stop...).

The attached patch applies against tomcat 5.5.27 and solves the problem. I am
not sure about the its righteousness, especially for the Valve stuff, but I
guess it is a good start.


-- 
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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 46221] Leak WebappClassLoader with commons-logging and log4j

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





--- Comment #8 from Arnaud de Bossoreille <de...@idm.fr>  2008-12-04 05:24:28 PST ---
Mark, yo're probably right when you say it is more an enhancement than a leak.
I could not reproduce it any more. It seems that sometimes the VM is more eager
to unload its classes. Some other times it requires dozens of start/stop to
finally unload the classes, even with forced GC calls.

However Peter pointed out a real leak which I was not able to reproduce too.
Can some objects be initialized in a different order that would explain that
kind of behavior?


-- 
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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 46221] Leak WebappClassLoader with commons-logging and log4j

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





--- Comment #4 from Arnaud de Bossoreille <de...@idm.fr>  2008-12-03 06:27:36 PST ---
I am also using the manager via the web interface but with the start/stop links
of the webapp.

I am a little bit confused by the plumbing of tomcat's objects, that is why I
do not always see what is involved. However it seems that your patch in
StandardPipeline.java is better than what I did in StandardContext.java for the
same purpose, because it handles more instances than those created by the
StandardContext.

My test showed that 3 valves are concerned by the releaseContainerLog calls.
But maybe not all of them have a reference on the WebappClassLoader (I did not
check). The valves I see (System.err.println(current);) are:

    - org.apache.catalina.core.StandardWrapperValve[jsp]
    - org.apache.catalina.core.StandardWrapperValve[default]
    - org.apache.catalina.core.StandardContextValve[/logging-leak]

I suppose my patch handled only the last one.

Moreover, you may have more valves than I have. This would explain why my patch
did not work for you (I guess).

I created the patch I last used so that you can review it (I will add it as a
new attachement).


-- 
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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 46221] Leak WebappClassLoader with commons-logging and log4j

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


Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
             Status|NEEDINFO                    |NEW




--- Comment #7 from Mark Thomas <ma...@apache.org>  2008-12-03 14:05:24 PST ---
I've done some more testing with several hundred undeploy/deploy cycles and
several hundred reload cycles of the test application provided in this report
and I do not see any memory leak.

I am changing the status of this issue to enhancement to reflect that clean-up
could occur early when a web app is stopped.


-- 
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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 46221] Leak WebappClassLoader with commons-logging and log4j

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

--- Comment #11 from Sylvain Laurent <sl...@apache.org> 2011-05-21 21:46:36 UTC ---
I cannot reproduce the problem with tc 7.0.14 nor 6.0.29. Is it really worth
fixing this in tc 5 ?

-- 
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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 46221] Leak WebappClassLoader with commons-logging and log4j

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





--- Comment #10 from Mauro Molinari <ma...@tiscali.it>  2009-01-12 03:49:00 PST ---
After giving a quick look at Tomcat6 sources, this problem seems to affect that
version of Tomcat6 too.

Mauro.


-- 
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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 46221] Leak WebappClassLoader with commons-logging and log4j

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


Mauro Molinari <ma...@tiscali.it> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mauromol@tiscali.it




--- Comment #9 from Mauro Molinari <ma...@tiscali.it>  2009-01-12 03:41:14 PST ---
Today I was trying to identify memory leaks in our webapp restart process and I
encountered this problem (the logger instance of StandardContext keeps a
reference to a logger that is loaded by the webapp class loader, so this can't
be garbage collected).
I gave a quick look to the attached patch and it seems to actually solve my
problem.
This is clearly a bug (not an enhancement!) because resources are not cleared
correctly by org.apache.catalina.core.StandardContext.stop().

I hope this will be fixed soon...

Mauro.


-- 
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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 46221] Leak WebappClassLoader with commons-logging and log4j

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


Peter Rossbach <pr...@objektpark.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO




--- Comment #3 from Peter Rossbach <pr...@objektpark.de>  2008-12-03 03:35:39 PST ---
I am not sure that your patch fix the bug really. I have test it with
deploy/undeploy via Manager API.
The result is after a while I got a OutOfMemory Exception a perm heap is full.

One thing that I change is deregister containerLog at all Context Valves at
StandardPipeline.

StandardPipeline.java
L 273
       while (current != null) {
            if (current instanceof Lifecycle)
                ((Lifecycle) current).stop();
            unregisterValve(current);
            if(current instanceof ValveBase)
                ((ValveBase)current).releaseContainerLog();
                current = current.getNext();
        }

More hints?

Peter


-- 
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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 46221] Leak WebappClassLoader with commons-logging and log4j

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





--- Comment #2 from Arnaud de Bossoreille <de...@idm.fr>  2008-11-17 04:21:32 PST ---
Created an attachment (id=22881)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=22881)
Patch which solves the problem


-- 
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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 46221] Leak WebappClassLoader with commons-logging and log4j

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

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX

--- Comment #12 from Mark Thomas <ma...@apache.org> 2011-06-22 18:51:06 UTC ---
My original testing was against Tomcat 5.5.x and there was no leak.

Given that the logger may still be used after the web application has stopped
(e.g. to log issues during undeployment) I don't - on reflection - see a need
for this enhancement.

-- 
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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 46221] Leak WebappClassLoader with commons-logging and log4j

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


Arnaud de Bossoreille <de...@idm.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #22881|0                           |1
        is obsolete|                            |




--- Comment #5 from Arnaud de Bossoreille <de...@idm.fr>  2008-12-03 06:30:03 PST ---
Created an attachment (id=22985)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=22985)
Second version of the patch


-- 
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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 46221] Leak WebappClassLoader with commons-logging and log4j

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





--- Comment #1 from Arnaud de Bossoreille <de...@idm.fr>  2008-11-17 04:20:27 PST ---
Created an attachment (id=22880)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=22880)
Simple test case

Use maven 2 to build it, a compiled war cannot be attached because of its size.


-- 
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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 46221] Leak WebappClassLoader with commons-logging and log4j

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

--- Comment #13 from Mauro Molinari <ma...@tiscali.it> 2011-06-22 18:57:35 UTC ---
(In reply to comment #12)
> My original testing was against Tomcat 5.5.x and there was no leak.

Well, Tomcat 5.5.x really had the leak! My comment #9 and the attached patch
explain and demonstrate this. The fact you don't want to fix it for 5.5 is
another story.

Regarding the latest versions of Tomcat 6.x and 7.x, I didn't have the time and
the chance to test.

-- 
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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 46221] Leak WebappClassLoader with commons-logging and log4j

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





--- Comment #6 from Mark Thomas <ma...@apache.org>  2008-12-03 10:44:20 PST ---
Using the provided test case I don't see any memory leaks. I do see various
references retained after the web application has been stopped but before it is
restarted / undeployed.

A leak would be when reloads lead to an increase in the number of instances of
a class, typically the webappclassloader, and I don't see that.

Yes, we could do a better job of cleaning up the logger references when the web
application stops but that is more an enhancement than a bug.

I'll set up a separate test for multiple deploy/undeploy to see if I can create
the issue Peter saw.


-- 
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: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org