1

I've been attempting to solve all memory leaks that prevent an application from reloading successfully on tomcat.

I first started with Tomcat logs saying the application had a thread that didn't stop (Eclipse EMF Reference Cleaner had to be disabled with org.eclipse.emf.common.util.ReferenceClearingQueue=false).

Then solving 2 ThreadLocals not properly handled on some libraries (updating them solved it).

Then, with the help of Eclipse Memory Analyzer (MAT) i found that the classloader was being retained by a JVM shutdownhook that Log4J2 uses (Programmatically disabling shutdown hook in log4j 2).

And now i don't get any Tomcat warning and MAT can't find any references to my classes other than weak/soft, but it still does not get Gargage Collected.

With MAT i can confirm that all my classes are retained twice:

MAT Histogram Merge Shortests Paths to GC Roots exclude all Weak/Soft/Phatom references

I have updated to latests Tomcat 9.0.74 and Eclipse Adoptium jdk-8.0.372.7-hotspot, but nothing has changed.

Tomcat logs don't show anything relevant on app restart (they did before solving thread locals and thread stopping)

abr 24, 2023 12:19:41 PM org.apache.catalina.core.StandardContext reload
INFORMACIÓN: Ha comenzado la recarga de Contexto [/test]
abr 24, 2023 12:19:41 PM com.sun.xml.ws.transport.http.servlet.WSServletDelegate destroy
INFORMACIÓN: WSSERVLET15: el servlet de JAX-WS se ha destruido
abr 24, 2023 12:19:41 PM com.sun.xml.ws.server.WSEndpointImpl closeManagedObjectManager
INFORMACIÓN: Closing Metro monitoring root: com.sun.metro:pp=/,type=WSEndpoint,name=/test-TestServerImplService-TestServerImplPort
abr 24, 2023 12:19:41 PM com.sun.xml.ws.transport.http.servlet.WSServletContextListener contextDestroyed
INFORMACIÓN: WSSERVLET13: el listener de contexto de JAX-WS se ha destruido

abr 24, 2023 12:20:06 PM org.apache.jasper.servlet.TldScanner scanJars
INFORMACIÓN: Al menos un JAR, que se ha explorado buscando TLDs, aún no contenía TLDs. Activar historial de depuración para este historiador para una completa lista de los JARs que fueron explorados y de los que nos se halló TLDs. Saltarse JARs no necesarios durante la exploración puede dar lugar a una mejora de tiempo significativa en el arranque y compilación de JSP .
abr 24, 2023 12:20:17 PM com.sun.xml.ws.server.MonitorBase createRoot
INFORMACIÓN: Metro monitoring rootname successfully set to: com.sun.metro:pp=/,type=WSEndpoint,name=/test-TestServerImplService-TestServerImplPort
abr 24, 2023 12:20:18 PM com.sun.xml.ws.transport.http.servlet.WSServletDelegate <init>
INFORMACIÓN: WSSERVLET14: inicializando el servlet de JAX-WS
abr 24, 2023 12:20:20 PM com.sun.xml.ws.transport.http.servlet.WSServletContextListener contextInitialized
INFORMACIÓN: WSSERVLET12: inicializando el listener de contexto de JAX-WS
abr 24, 2023 12:20:20 PM org.apache.catalina.core.StandardContext reload
INFORMACIÓN: Se ha completado la recarga de este Contexto
  • What is your garbage collection scheme you added into setenv.sh in tomcat? Did you assign a G1 garbage collector? Or did you call System or runtime gc() ,of I might add would be unhelpful if it were associated with a thread that is simply shutting down! – Samuel Marchant Apr 24 '23 at 11:47
  • I was using the default GC (Parallel?), but i've tried G1 and the leak is still present. For what i know, analyzing with MAT does not need a previous GC because it computes object visibility, but i also clicked on "Perform GC" within VisualVM. Also, you can call manual GC to free memory before it's needed, but you shouldn't get an OutOfMemory when reloading several times if it's not really retained by something outside the app classloader created by Tomcat – Sergio Otero Lopez Apr 24 '23 at 12:33
  • I'd then take a very careful look at the server startup command line environments for everything configured, particularly the -Xms -Xmx -Xss.see that they are calculated properly. You may want to take a look in this could help also, it's very tough at this time, and the early docs on server memory alloc were beaten around by data loss from crashes beyond my control but not dangerous in the docs. https://drive.google.com/file/d/1gjHmdC-BW0Q2vXiQYmp1rzPU497sybNy/view?usp=drivesdk – Samuel Marchant Apr 24 '23 at 12:42

1 Answers1

1

Don't lost your time for fix it, it is an very old bug, which is not fixing. Even if you use redoploy it is not helping. So use restart or shift to another alternatives like payara or glassfish.

More details for this bug: Memory leak when redeploying application in Tomcat

utrucceh
  • 1,076
  • 6
  • 11