[#4403] - Another ThreadLocal leak

Category:
Bug report
Priority:
Normal
Status:
New
Project: Severity:
Major
Resolution:
Open
Component: Reproducibility:
Always
Assigned to:
1

More threadlocal leaks, an API to shutdown these needs to be implemented.
I can't shutdown

GRAVE: The web application [/] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@604c492e]) and a value of type [java.lang.Class] (value [class Conta_FatAgrDataSet_1428677141286_420825]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Abr 10, 2015 12:38:43 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
GRAVE: The web application [/] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@604c492e]) and a value of type [java.lang.Class] (value [class Conta_FatAgrDataSet_1428680257414_334538]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Abr 10, 2015 12:38:43 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
GRAVE: The web application [/] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@604c492e]) and a value of type [java.lang.Class] (value [class SubRelHistoricoConsumo_1428680256726_123478]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Abr 10, 2015 12:38:43 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
GRAVE: The web application [/] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@604c492e]) and a value of type [java.lang.Class] (value [class Conta_FatAgrDataSet_1428679366318_644315]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Abr 10, 2015 12:38:43 PM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
GRAVE: The web application [/] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@604c492e]) and a value of type [java.lang.Class] (value [class SubRelHistoricoConsumo_1428679434364_224304]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak

v6.0.3
sergio.rolanski's picture
Joined: Mar 2 2015 - 12:15pm
Last seen: 4 years 3 months ago

6 Comments:

#1
  • Assigned:nobody»

Seems classFromBytesRef was created to fix a crash in JVM, has been around since version 2.0 according to grepcode.
It might not be needed anymore.

Add this workaround in the destroy() of a ServletContextListener implementation:

private void fixJasperLocalThread() {
fixJasperLocalThread(FontUtil.class, "threadMissingFontsCache");
fixJasperLocalThread(JRAbstractJavaCompiler.class, "classFromBytesRef");
}

private void fixJasperLocalThread(Class<?> clazz, String fieldName) {
try {
Field field = clazz.getDeclaredField(fieldName);
if (field != null) {
field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(null, null);
}
} catch (IllegalAccessException | NoSuchFieldException | SecurityException ex) {
// ignorado
}
}

#2
  • Assigned:nobody»

Just downloaded 6.2 of Jaspersoft server.
Still see: Threads are going to be renewed over time to try and avoid a probable memory leak.
in the apache-tomcat\logs\jasperreportstomcat-stderr.2015-12-10.log
Is this something to be concerned about.
If so what is the fix, please be succinct and correct.

#3

Add the following line to WEB-INF/classes/jasperreports.properties to avoid this particular ThreadLocal problem:

net.sf.jasperreports.evaluator.class.reference.fix.enabled=false

Regards,
Lucian

#4

I did that and I still get memory leaks.
If you look at my first post you will see it does assign null to the static attribute in class FontUtil.
This seems to fix half of the problem.

Dez 11, 2015 10:31:40 org.apache.catalina.loader.WebappClassLoader
ERROR: The web application [/] created a ThreadLocal with key of type [net.sf.jasperreports.engine.fonts.FontUtil$1] (value [net.sf.jasperreports.engine.fonts.FontUtil$1@3a5aa11a]) and a value of type [java.util.HashSet] (value ) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Dez 11, 2015 10:31:40 org.apache.catalina.loader.WebappClassLoader
ERROR: The web application [/] created a ThreadLocal with key of type [net.sf.jasperreports.engine.fonts.FontUtil$1] (value [net.sf.jasperreports.engine.fonts.FontUtil$1@3a5aa11a]) and a value of type [java.util.HashSet] (value ) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Dez 11, 2015 10:31:40 org.apache.catalina.loader.WebappClassLoader
ERROR: The web application [/] created a ThreadLocal with key of type [net.sf.jasperreports.engine.fonts.FontUtil$1] (value [net.sf.jasperreports.engine.fonts.FontUtil$1@3a5aa11a]) and a value of type [java.util.HashSet] (value ) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Dez 11, 2015 10:31:40 org.apache.catalina.loader.WebappClassLoader
ERROR: The web application [/] created a ThreadLocal with key of type [net.sf.jasperreports.engine.fonts.FontUtil$1] (value [net.sf.jasperreports.engine.fonts.FontUtil$1@3a5aa11a]) and a value of type [java.util.HashSet] (value ) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Dez 11, 2015 10:31:40 org.apache.catalina.loader.WebappClassLoader
ERROR: The web application [/] created a ThreadLocal with key of type [net.sf.jasperreports.engine.fonts.FontUtil$1] (value [net.sf.jasperreports.engine.fonts.FontUtil$1@3a5aa11a]) and a value of type [java.util.HashSet] (value ) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Dez 11, 2015 10:31:40 org.apache.catalina.loader.WebappClassLoader
ERROR: The web application [/] created a ThreadLocal with key of type [net.sf.jasperreports.engine.fonts.FontUtil$1] (value [net.sf.jasperreports.engine.fonts.FontUtil$1@3a5aa11a]) and a value of type [java.util.HashSet] (value ) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Dez 11, 2015 10:31:41 org.apache.catalina.startup.HostConfig
INFO: Undeploying context [/]

#5

Right, net.sf.jasperreports.evaluator.class.reference.fix.enabled only addresses the specific problem that the original bug description and comment #1 talk about.

There are other similar problems (more ThreadLocals) for which I don't think that we have a solution at the moment. We'll have to go into the code and see if we can dispense of each ThreadLocal.

#6

We are also facing memory leaks due to net.sf.jasperreports.engine.fill.JRVirtualizationContext.contexts storing huge object reference in tomcat threadlocal. Please let me know what we can do. Our application is a web application.

Feedback
randomness