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
ClassLoader leak with Jetty and Karaf - static instances of java.lang.Throwable #868
Comments
PR #869 uses subclasses of |
@grgrzybek this is surprising. Actually, I am more inclined to think it's a JVM bug. Java application code should not bother about magic hidden fields, no matter what the application does. Even using the 4 arguments constructor, I don't see any guarantee that the |
@sbordet I checked before&after heap dumps and looks like it helps with ClassLoader actually being GCed - no references kept in Throwables created with There's similar issue with JGit: https://github.com/eclipse/jgit/blob/master/org.eclipse.jgit/src/org/eclipse/jgit/errors/StopWalkException.java#L56 and same fix (4 argument Exception constructor) helps. Of course I can't be sure some native code actually writes to this field, I'm also not sure how BacktraceBuilder class... But my fix looks promising for now. Javadoc for 4 argument
which is what we need - no |
@grgrzybek then rather than applying the 4 args constructor in all the places, I'd prefer to have a utility class, say Can you comply with the required checks and update your PR ? Thanks ! |
Signed-off-by: Grzegorz Grzybek <gr.grzybek@gmail.com>
@sbordet sure! I'll refactor private |
Signed-off-by: Grzegorz Grzybek <gr.grzybek@gmail.com>
Signed-off-by: Grzegorz Grzybek <gr.grzybek@gmail.com>
Signed-off-by: Grzegorz Grzybek <gr.grzybek@gmail.com>
Signed-off-by: Grzegorz Grzybek <gr.grzybek@gmail.com>
@grgrzybek just do 9.2.x, we'll do the merge with the other branches. |
Issue #868 - Use static Throwables without backtrace/stackTrace
@janbartel thanks for merging! |
@grgrzybek I'll close it when I'm done merging. Thanks. |
Committed to jetty-9.2.x and merged to jetty-9.3.x jetty-9.4.x and master. |
@janbartel many many thanks! |
@grgrzybek thank you for the pull request. |
There's magical (not visible via reflection, only in memory dumps) field inside
java.lang.Throwable
class calledbacktrace
(source code).At runtime, in native code, this field is filled with array of Objects which are actually
java.lang.Class
instances - and we know how sensitive they are in dynamic classloader environments.In Karaf, through
pax-web-jetty
, when pax-web bundles are restarted without touching jetty bundles we have a memory leak visible in visualvm:The problem is with static instances of Throwable classes. They keep backtraces filled with Classes+ClassLoaders from previous incarnations of other bundles - depending on the time when the static
Throwable
was created.Here are static throwables found in
jetty-9.2.17.v20160517
:Actually, for JDK 7+ the fix is simple, PR in next comment.
The text was updated successfully, but these errors were encountered: