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

Camel leaks memory on undeploy / redeploy in app server when JMX enabled and createConnector = true

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.10.0
    • 2.9.6, 2.10.4, 2.11.0
    • camel-jmx
    • None
    • Unknown

    Description

      We have embedded Camel in an EAR that we deploy to Weblogic. The Camel context is configured via Spring:

          <camelContext id="camel" handleFault="true" autoStartup="{{autoStartup}}" xmlns="http://camel.apache.org/schema/spring">
              <contextScan />
              <jmxAgent id="camelAgent" createConnector="true" registryPort="{{jmxPort}}" />
          </camelContext>

      You can see that we create a JMX connector to allow for remote management.

      However, we have run into PermGen space issues, because our application is leaking class loaders when the application is undeployed or redeployed.

      After digging around (and addressing some Jasper Reports ThreadLocal sloppiness), it appears that the only issue left is that the sun.rmi.transport.ObjectTable class maintains a static reference to all available RMI targets. Unfortunately, one of these targets is the JMX connector created by Camel, which was obviously loaded via our application's classloader.

      Thus, ObjectTable has a static reference to the Camel JMX RMI target, which has a reference to the app's class loader, which in turn has references to all classes loaded (and generated) for that single deployment of the application – and none of these classes can be GC'ed.

      After digging through the code for Camel's DefaultManagementAgent, I'm inclined to believe that the fix is fairly simple:

      1. Update createJmxConnector(String) to cache the reference to the created Registry in an instance variable.
      1. Update doStop() to check if we have a cached Registry instance, and if we do, call UnicastRemoteObject.unexportObject(registry, true);

      Some app servers have workarounds for this sort of leak (see "RMI targets" in Table 1 at [1]), but Weblogic doesn't seem to.

      I'll also attach a screenshot of the memory analysis (more info at [2]).

      [1] http://pic.dhe.ibm.com/infocenter/wasinfo/v8r5/index.jsp?topic=%2Fcom.ibm.websphere.express.doc%2Fae%2Fctrb_memleakdetection.html

      [2] http://www.yourkit.com/docs/kb/class_loaders.jsp

      Attachments

        1. camel-5907.patch
          5 kB
          Daniel Gredler
        2. leak.png
          238 kB
          Daniel Gredler

        Activity

          People

            njiang Willem Jiang
            sdanig Daniel Gredler
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: