-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
ThreadLocal Memory Leak: com.codahale.metrics.ThreadLocalRandom #742
Comments
I'm open to adding a clean up mechanism and ServletContextListener, but ideally we'd make it completely transparent to the user. |
I have also observed that this ThreadLocal classloader leak occurs on other persistent app server threads like Jetty's Scanner Thread. During deployment it probably touches every class once which initializes the static ThreadLocal field in ThreadLocalRandom. So without any request the deployed app can not be garbage collected anymore. To fix all possible leaks metrics would need to:
Alternatively for Java7+ users it might be possible to provide a separate metrics-core library that uses java.util.concurrent.ThreadLocalRandom of Java7+. In that case the classloader leak would be gone as ThreadLocalRandom would be loaded by the system classloader. |
Where does this issue currently stand? Curious about if someone is working on it or not. |
Would a patch be accepted that copied over the updated improvements from some of the updated source? http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/main/java/util/concurrent/ThreadLocalRandom.java?view=markup |
So was doing some digging around to see if I could get something to work, but it looks like what the Java 7 of ThreadLocalRandom is using for its seeding (declared fields in class |
…cat can handle it (even though it logs a stupid severe warning).
Using dropwizard 3.1.0(core) with Jdk7 and jboss8. Observing threadlocal related memory issues....any fix to overcome this? |
How to use Java7's ThreadLocalRandom to avoid Thread local related issues? |
@nani83 checkout the 3.1 branch, delete ThreadLocalRandom from Metrics and fix imports so it uses the Java7 version. |
Thanks. Since, it is manual, I thought there might be another way/version which I can use. Will check this. Another query, As you were mentioning in previous post, Do we need explicit cleanup of threadlocals in filters/listener to overcome this issue completely? |
What is the status of this issue? We're having the same problem I think. When we issue the command
|
Hey all, just wanted to say we've forked this repo and back ported the fix (diff) (it wont work on java6) from @DustinChaloupka (#757) over under banno/metrics. |
@adamdecaf , will you issue a pull request to @ryantenney ? Is there any plan for the code to come back into this repo? |
@philippe-tr The fix was already committed to dropwizard/master. So everyone is free to cherry-pick that off. The rest of the changes were just to get the versions correct when packaging the jar. |
Ok. Too bad it did not make it to a release packaged on maven central. I can make my own in-house release for now I suppose. |
@philippe-tr yea, I didn't want to deal with that, and we have an internal repository we use. |
@philippe-tr Did this resolve your issue? I am experiencing the same first error message as you, even with the cherry-pick on top of 3.1.0.
Any idea of how to resolve? |
@horn-rimmed-glasses No I did not work through this yet. |
Any news on this? |
We're still running our fork of this library. Has there been much development on this project? |
+1 |
Is this still leaking in 3.1.2? |
I still have this issue on latest. |
We're still on the fork I've mentioned previously on this. |
any update on this? when can we expect a fix for this? |
+1 |
Submitted #1052 to fix this for the 3.1 branch. |
I guess it should be fixed by #1052 |
Just in case it is useful for somebody, this problem is still happening in 3.2.2 on Java 6. If I am correct, this is because #1052 fixes the problem for JDK7 and above. Another argument for convincing management to invest time in updating Java... |
Yes. Unfortunately, it's not possible to patch the internal |
I had similar problem and I implemented a different ThreadLocal class that will enable class loaders to be GC-ed on redeploy. It is different than other similar attempts (like VicariousThreadLocal and other classes) because it is completely non-blocking (even for setting values, not only for getting). |
Using Metrics 3.1.0 there is a static
ThreadLocal
incom.codahale.metrics.ThreadLocalRandom
that is never cleaned up.This causes app server threads to hold references to this
ThreadLocalRandom
and thus the app ClassLoader can never be garbage collected.It is a common misunderstanding that the
ThreadLocalMap.Entry
class prevents such leaks as it extendsWeakReference
. However theEntry
class only weakly references the key (theThreadLocal
instance) and not the value (thecom.codahale.metrics.ThreadLocalRandom
instance).So when a web app gets undeployed then the weakly referenced
ThreadLocal
instance might get cleaned up but the correspondingThreadLocalMap.Entry
instance is still in the map and still holds a strong reference to its value.ThreadLocalMap
has some code to detect these stale entries but this code only gets triggered when callingThreadLocal.set()
orThreadLocal.remove()
... which does not happen here.The above screenshot shows the GC root excluding
WeakReference
to further illustrate that the leak exists and is caused by theThreadLocal.ThreadLocalMap.Entry.value
field.Either do not use
ThreadLocal
or provide a clean up mechanism that can be called in aServletContextListener
.The text was updated successfully, but these errors were encountered: