Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guice + Tomcat potential memory leak #630

Closed
gissuebot opened this issue Jul 7, 2014 · 8 comments
Closed

Guice + Tomcat potential memory leak #630

gissuebot opened this issue Jul 7, 2014 · 8 comments

Comments

@gissuebot
Copy link

From pas256 on May 17, 2011 12:39:04

I have just started using Google Guice with my Tomcat webapp, and have noticed the following in the catalina.out file whenever the WAR file is undeployed:


May 16, 2011 5:37:24 PM org.apache.catalina.startup.HostConfig checkResources INFO: Undeploying context [/app]

May 16, 2011 5:37:24 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: A web application appears to have started a thread named [com.google.inject.internal.util.$Finalizer] but has failed to stop it. This is very likely to create a memory leak.

May 16, 2011 5:37:24 PM org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap SEVERE: A web application created a ThreadLocal with key of type [null] (value [com.google.inject.internal.InjectorImpl$1@10ace8d]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@7e9bed]) but failed to remove it when the web application was stopped. To prevent a memory leak, the ThreadLocal has been forcibly removed.

I am not sure what causes this, or how I can stop it from happening.

I have only followed the instructions from here: https://code.google.com/docreader/#p=google-guice&s=google-guice&t=ServletModule ... and haven't done anything fancy with it yet. I just have 2 servlets and a filter.

This issue is also posted on StackOverflow: http://stackoverflow.com/questions/6025089/guice-tomcat-potential-memory-leak

Original issue: http://code.google.com/p/google-guice/issues/detail?id=630

@gissuebot
Copy link
Author

From cgdecker on May 17, 2011 09:49:06

See issue 288 .

@gissuebot
Copy link
Author

From sberlin on May 17, 2011 10:05:58

(No comment was entered for this change.)

Status: Invalid

@gissuebot
Copy link
Author

From tj.rothwell on November 10, 2011 10:32:49

+sberlin, Could you help me understand why this is invalid?

It appears that InjectorImpl creates a ThreadLocal. Could GuiceFilter or GuiceServletContextListener be used to clean it up?

@gissuebot
Copy link
Author

From pas256 on November 10, 2011 11:03:36

Yeah, I don't understand what is happening in Issue 288 , but I guess it's related.

I think he meant Duplicate not Invalid.

It was also meant to be fixed in version 2.0... version 3.0 is out and still not fixed so go figure. Fingers crossed for 3.1

@gissuebot
Copy link
Author

From tj.rothwell on November 10, 2011 11:15:09

+pas256, Guava doesn't use FRQ anymore which fixes the Thread not stopping. You can use sisu-guice w/ guava 10.0.1 or build from the latest guice.

The Thread & ThreadLocal from the initial report are not the same thing.

@gissuebot
Copy link
Author

From mcculls on November 10, 2011 11:25:10

Issue 288 (the background finalizer thread) will be fixed when the Guava dependency is upgraded to r10 +

The ThreadLocal reported by Tomcat is separate - this is actually a simple Object array of length 1 which is used to manage contexts during injection. The array element is guaranteed to be null outside of any call to the injector so it won't cause any leak. The ThreadLocal will be reclaimed after the injector is no longer referenced. However it may appear to stay around for longer if you use reflection to peek into the ThreadLocal map like Tomcat does, due to the current JDK ThreadLocal implementation.

Status: Duplicate
Mergedinto: 288

@gissuebot
Copy link
Author

From pas256 on November 10, 2011 11:29:13

Ah thanks for the details.

@gissuebot
Copy link
Author

From lauri.lehmijoki on January 14, 2013 06:09:28

Our Tomcat also complains about this.

Because of this shortcoming in Guice, we cannot use Tomcat Manager to re-deploy our software. If we would use Manager, we would eventually run out of PermGen space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant