Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-2985

Memory leak when initializing CXF throughSpring

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.2.10
    • Fix Version/s: 2.2.11
    • Component/s: Bus
    • Labels:
      None

      Description

      As described in a comment of bug CXF-2164, there's still a case of memory leak produced by CXF when embedded into a web application and initialized through Spring.

      The problem is that cxf.xml declares the following bean:

      <bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl"/>

      Here, the destroy-method is not declared. This means that when Sping shuts down the context, it does not call any shutdown method on the CXFBusImpl.

      The net result is the following:

      • Tomcat starts
      • Tomcat starts my web application
      • this declares a Spring web application context that gets parsed
      • at some point cxf.xml is parsed, so the bean named cxf is created and an org.apache.cxf.bus.CXFBusImpl instance is created using the constructor org.apache.cxf.bus.CXFBusImpl.CXFBusImpl(Map<Class, Object>), which causes the org.apache.cxf.BusFactory.localBus ThreadLocal to be assigned a value of this type, through a call to org.apache.cxf.BusFactory.possiblySetDefaultBus(Bus); I see that this happens in a thread called "main"
      • if I stop the web application, Spring closes down the context; however, as I said before, this does not cause any shutdown method of the cxf bean to be called
      • so there's no null-setting or removing operation of the org.apache.cxf.BusFactory.localBus ThreadLocal for the thread "main"

      The problem of the use of a ThreadLocal is that even if the shutdown method od CXFBusImpl were called, the shutdown operation may be done in a thread which is different from the one in which the context had been created.

      As suggested by Daniel Kulp in the other report, maybe the best solution is to use a WeakHashMap<Thread, Bus> to keep the thread-bus relationships.
      I'm going to provide a patch.

        Attachments

        1. Patch_CXF-2985.patch
          5 kB
          Mauro Molinari

          Activity

            People

            • Assignee:
              dkulp Daniel Kulp
              Reporter:
              mauromol Mauro Molinari
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: