Tuscany
  1. Tuscany
  2. TUSCANY-3770

Tomcat 7 reports a memory leak when stopping a Tuscany webapp

    Details

      Description

      On Tomcat 7, when a Tuscany webapp is stopped, the following message is displayed:
      SEVERE: The web application [/sample-calculator-webapp] created a ThreadLocal with key of type [null] (value
      [org.apache.tuscany.sca.core.invocation.ThreadMessageContext$1@1b071c0]) and a value of type
      [org.apache.tuscany.sca.core.invocation.MessageImpl] (value [org.apache.tuscany.sca.core.invocation.MessageImpl@fbf51d])
      but failed to remove it when the web application was stopped. This is very likely to create a memory leak.

      This happens because Tuscany adds a thread-local ThreadMessageContext object to every invocation thread when starting a request invocation and doesn't remove this object when the request is complete.

      There is code in WebAppServletHost.destroy() that attempts to remove this context information when the webapp is stopped. This usually doesn't succeed in removing the context information because the ThreadLocal.remove() method only removes context information from the current thread and not from other threads. There's no Java API for removing this information from other threads.

      The only way to remove this information is to track the completion of each request invocation and remove the context information from the current thread when the request has been completed. The context information will be recreated for the next request on the thread. This is very easy to implement by adding a few lines of code to the ThreadMessageContext class.

        Activity

        Hide
        Simon Nash added a comment -

        My fix seems to be working OK so I've committed it to the 1.x trunk under revision r1033012.

        Unless anyone has concerns I'll also include this change in 1.6.1 RC2.

        Show
        Simon Nash added a comment - My fix seems to be working OK so I've committed it to the 1.x trunk under revision r1033012. Unless anyone has concerns I'll also include this change in 1.6.1 RC2.
        Hide
        Simon Nash added a comment -

        Fixed under revision r1033012 in the 1.x trunk and revision r1033692 in the 1.6.1 branch.

        Show
        Simon Nash added a comment - Fixed under revision r1033012 in the 1.x trunk and revision r1033692 in the 1.6.1 branch.
        Hide
        Simon Laws added a comment -

        A patch for the 2.x code base. Want to do this fix separately so I can be sure I'm not messing anything up.

        Show
        Simon Laws added a comment - A patch for the 2.x code base. Want to do this fix separately so I can be sure I'm not messing anything up.

          People

          • Assignee:
            Simon Nash
            Reporter:
            Simon Nash
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development