-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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: DEFAULT_ANNOTATION_INTROSPECTOR holds annotation reference (JBoss) #3771
Comments
I have uploaded a reproducer here: https://github.com/ciis0/jackson-3771 |
I'd say this should be fixed by JBoss. That LRUMap can readily be garbage collected. @cowtowncoder might have his own opinion but to me, I would need to be convinced why this is not a JBoss issue. |
In theory, Jackson could use a WeakHashMap instead of LRUMap but JBoss may still fail to clean up other Jackson refs. |
Ah, this is hidden away in #3093: the LRUMap is (indirectly) referenced via a static field in I have updated the description. |
i.e. the problem is not that the LURMap is not cleaned up, but that the LRUMap contains keys from another class-loader and with this keeps alive the other classloader until jackson's classloader is cleaned up -- which does not happen at runtime, you have to restart JBoss for that. |
Maybe a clear method on the Annotation inspector could allow users to clear up that old data |
Ah. Ok now it all makes sense. Series of unfortunate events, unintended side effects. So it's due to 2 things:
Although (2) might be initially easier, I think (1) might actually make more sense: without resolving that there would still be possibility of retention via non-static references. Use of arbitrary Class instances as keys tends to lead to hard to track down retention. A simple way that I'll probably is to use Unfortunately fix needs to go in 2.15.0, I think, just due to risk involved (no API change needed). |
@cowtowncoder there is com.fasterxml.jackson.databind.type.ClassKey which seems to have been written for this purpose. But it might keep unwanted references too. It might be worth reviewing if ClassKey needs to be rewritten too - to drop the Class<?> refs and only keep the name. |
@pjfanning That's something to consider too I suppose, although its actually usage should be less problematic as lookup maps are bound to individual Having said that.... I am starting to think that maybe |
Ok, not so fast I guess. The problem is not just What I'll do is create separate issue for follow-up work to do that refactoring. |
Created #3772 for follow up work. Also starting to think this might be one of bad speculative optimizations, overall, given that without this |
Describe the bug
A clear and concise description of what the bug is.
Similar to #3093, in JBoss
JacksonAnnotationIntrospector._annotationsInside
, referenced statically viaObjectMapper.DEFAULT_ANNOTATION_INTROSPECTOR
, might contain references to annotations from Deployment Class-Loaders, which leads to leaking those when the deployment is stopped/undeployed.Version information
Which Jackson version(s) was this for?
2.13.4.2, but from the code it looks like it's still true today.
jackson-databind/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Line 375 in de62c67
jackson-databind/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java
Line 82 in de62c67
jackson-databind/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java
Line 162 in de62c67
To Reproduce
https://github.com/ciis0/jackson-3771
Expected behavior
If reproduction itself needs further explanation, you may also add more details here.
Additional context
Add any other context about the problem here.
Reference to annotation class from deployment class-loader in
JacksonAnnotationIntrospector
instance:Static reference to that annotation introspector instance from
ObjectMapper
:The text was updated successfully, but these errors were encountered: