Details
-
Bug
-
Resolution: Unresolved
-
None
-
1.6.x
-
None
-
Operating System: All
Platform: All
-
major
-
P1
-
266
Description
Recently after a long time log4j got it's problem with clearing the MDC context and the underlying ThreadLocal Hashmap fixed. S. https://issues.apache.org/bugzilla/show_bug.cgi?id=50486
This fixed a long running Problem with Tomcat freeing memory on reload.
In order to do so, log4j's MDC got the clear method with 1.2.16 and with 1.2.17 fixed it so that it works.
Log4j has an MDC adaptor for Log4J and it's own clear method. But instead of calling Log4J's clear it implements essentially (MDC.getContext()).clear() which only clears the HashMap but doesn't remove it from the ThreadLocal context resulting in a MemroryLeak.
Short workaround: Instead of calling slf4j's MDC.clear() call log4j's MDC.clear() (but that is the exact opositit of what slf4j is made for)
Simple Fix: change log4j's mdc adaptor to call MDC.clear() instead of MDC.getContext().clear().
More complex fix: If backward compatibility is an issue (like it was für log4j) than log4js solution can be applied here: Instead of calling MDC.clear() directly call it via reflexion if it exists and otherwise keep calling MDC.getContext().clear().