Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-17712

Memory leak in DefaultCamelContext reported by Tomcat 10

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 3.14.1
    • 3.17.0
    • came-core
    • None
    • Apache Camel 3.14.1

      Tomcat 10

      Java 17

    • Moderate

    Description

      Hello,
      we are using Camel inside a Tomcat application. The application also supports reloading of the context.
      Unfortunately, we are getting a memory leak report, e.g.

      [Catalina-utility-1] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [java.lang.ThreadLocal.SuppliedThreadLocal] (value [java.lang.ThreadLocal$SuppliedThreadLocal@588bee00]) and a value of type [org.apache.camel.impl.DefaultCamelContext.OptionHolder] (value [org.apache.camel.impl.DefaultCamelContext$OptionHolder@1d5c4495]) 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.

       

      Looking at the code, the problem is within the java class DefaultCamelContext
      https://github.com/apache/camel/blob/main/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java

      It contains a class variable which is always instantiated with:
      ThreadLocal<OptionHolder> OPTIONS = ThreadLocal.withInitial(OptionHolder::new);

      This ThreadLocal is never cleaned up by OPTIONS.remove(), This should be added to the shutdown() or stop() handler maybe
      Some additional null checks would have to be implemented as well to make it safe.

       

      Thanks,
      Thomas

      Attachments

        Issue Links

          Activity

            People

              davsclaus Claus Ibsen
              tom_s4t Thomas Hoffmann
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: