glassfish
  1. glassfish
  2. GLASSFISH-18650

Memory leak with tag-files and CDI enabled

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 3.1.2
    • Fix Version/s: 4.0_b88_RC4
    • Component/s: web_container
    • Labels:
      None
    • Environment:

      Windows7 64bit with jdk7_u3, linux with jdk6, Glassifish Open Source 3.1.2

      Description

      When CDI is enabled on a web application which uses JSP tag files instances of tag files remain inside com.sun.enterprise.container.common.impl.managedbean.ManagedBeanManagerImpl in jcdiManagedBeanInstanceMap.

      Instances of tag files contains references to JspContext which contains a reference to JspWriterImpl, which contains a buffer which holds response data

      This is a memory leak which leads to OutOfMemoryErrors very quickly

        Activity

        Hide
        enrico_olivelli added a comment -

        attaching a simple test case

        Show
        enrico_olivelli added a comment - attaching a simple test case
        Hide
        enrico_olivelli added a comment -

        Steps to reproduce:

        • run the sample project
        • run the test
        • take and heap dump of Glassfish
        • look for "mytag" instances
        Show
        enrico_olivelli added a comment - Steps to reproduce: run the sample project run the test take and heap dump of Glassfish look for "mytag" instances
        Hide
        enrico_olivelli added a comment -

        any news on this issue ?

        Show
        enrico_olivelli added a comment - any news on this issue ?
        Hide
        pukkaone added a comment -

        A custom tag implemented as a Simple Tag Handler by extending the SimpleTagSupport convenience class also exhibits exactly the same symptoms.

        Show
        pukkaone added a comment - A custom tag implemented as a Simple Tag Handler by extending the SimpleTagSupport convenience class also exhibits exactly the same symptoms.
        Hide
        Sivakumar Thyagarajan added a comment -

        Transferring this issue to JJ Snyder.

        Show
        Sivakumar Thyagarajan added a comment - Transferring this issue to JJ Snyder.
        Hide
        shreedhar_ganapathy added a comment -

        Hi JJ
        The issue is fairly old. Is this issue reproducible with latest builds?
        Could you provide an update?

        Show
        shreedhar_ganapathy added a comment - Hi JJ The issue is fairly old. Is this issue reproducible with latest builds? Could you provide an update?
        Hide
        mtaube added a comment -

        This is still happening on the latest build. WebContainer.createTagHandlerInstance is causing ManagedBeanManagerImpl.createManagedBean to be called to instantiate the tag, but the corresponding .destroyManagedBean is never called, hence the leak.

        Show
        mtaube added a comment - This is still happening on the latest build. WebContainer.createTagHandlerInstance is causing ManagedBeanManagerImpl.createManagedBean to be called to instantiate the tag, but the corresponding .destroyManagedBean is never called, hence the leak.
        Hide
        Martin Grebac added a comment -

        Why was this assigned to me?

        Show
        Martin Grebac added a comment - Why was this assigned to me?
        Hide
        Shing Wai Chan added a comment -

        The calling stack is as follows:

         com.sun.enterprise.web.WebContainer.createTagHandlerInstance(WebContainer.java:1043)
        	at com.sun.enterprise.web.jsp.ResourceInjectorImpl.createTagHandlerInstance(ResourceInjectorImpl.java:104)
        	at org.apache.jsp.index_jsp._jspx_meth_my_mytag_0(index_jsp.java:86)
        	at org.apache.jsp.index_jsp._jspService(index_jsp.java:63)
        	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
        	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
        	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
        

        I see ResourceInjectorImpl#preDestroy which is not invoked.

        Show
        Shing Wai Chan added a comment - The calling stack is as follows: com.sun.enterprise.web.WebContainer.createTagHandlerInstance(WebContainer.java:1043) at com.sun.enterprise.web.jsp.ResourceInjectorImpl.createTagHandlerInstance(ResourceInjectorImpl.java:104) at org.apache.jsp.index_jsp._jspx_meth_my_mytag_0(index_jsp.java:86) at org.apache.jsp.index_jsp._jspService(index_jsp.java:63) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) I see ResourceInjectorImpl#preDestroy which is not invoked.
        Hide
        Shing Wai Chan added a comment -

        Assign to Kinman to further to investigate the jsp part.

        Show
        Shing Wai Chan added a comment - Assign to Kinman to further to investigate the jsp part.
        Hide
        kchung added a comment -

        The JSP compiler is generating calls to the injection manager to process annotations when the tag file instance is created, without calling preDestroy after doTag, causing memory leaks. This is wrong, because annotations are not supported for JSP tag files. Removing the calls to the injection manager should fix this problem.

        Show
        kchung added a comment - The JSP compiler is generating calls to the injection manager to process annotations when the tag file instance is created, without calling preDestroy after doTag, causing memory leaks. This is wrong, because annotations are not supported for JSP tag files. Removing the calls to the injection manager should fix this problem.
        Hide
        kchung added a comment -

        Upon closer examination, I failed to see the reported memory leakage.

        Running the test quickly lead to "error:java.net.NoRouteToHostException: Can't assign requested address", probably due too many open connections.

        The memory usage when running the test did increase monotonically, but at a rate that is acceptable, due probably to unclosed open connections. The behavior is similar for plain JSP pages, not just for tag files.

        As far as I can tell, the buffer is released after the request returns.

        There is still the issue of calling the injection manager unnecessarily. This should be fixed in a future release.

        Show
        kchung added a comment - Upon closer examination, I failed to see the reported memory leakage. Running the test quickly lead to "error:java.net.NoRouteToHostException: Can't assign requested address", probably due too many open connections. The memory usage when running the test did increase monotonically, but at a rate that is acceptable, due probably to unclosed open connections. The behavior is similar for plain JSP pages, not just for tag files. As far as I can tell, the buffer is released after the request returns. There is still the issue of calling the injection manager unnecessarily. This should be fixed in a future release.
        Hide
        mtaube added a comment -

        I saw the java.net.NoRouteToHostException happen on MacOS, just add a Thread.sleep(500) to the loop in the test and that problem goes away.

        Show
        mtaube added a comment - I saw the java.net.NoRouteToHostException happen on MacOS, just add a Thread.sleep(500) to the loop in the test and that problem goes away.
        Hide
        jjsnyder83 added a comment -

        Tag libraries are supported for cdi integration. There is a cdi tck test for this so disabling it will cause the cdi tck to fail. Please do not disable it! Also I think acustom tag implemented as a Simple Tag Handler by extending the SimpleTagSupport convenience class also exhibits exactly the same symptoms.

        Show
        jjsnyder83 added a comment - Tag libraries are supported for cdi integration. There is a cdi tck test for this so disabling it will cause the cdi tck to fail. Please do not disable it! Also I think acustom tag implemented as a Simple Tag Handler by extending the SimpleTagSupport convenience class also exhibits exactly the same symptoms.
        Hide
        aosama added a comment -

        guys i am facing the same issue , the tag handler is eating up the memory real quick

        can we have a quick fix for this

        Show
        aosama added a comment - guys i am facing the same issue , the tag handler is eating up the memory real quick can we have a quick fix for this
        Hide
        kchung added a comment -

        I am sending you a patch that may fix your issue. Can your give it a try and let me know?

        Show
        kchung added a comment - I am sending you a patch that may fix your issue. Can your give it a try and let me know?
        Hide
        kchung added a comment -

        Oops! aosama, what's your email? You can send that info to kinman.chung@oracle.com. Thanks.

        Show
        kchung added a comment - Oops! aosama, what's your email? You can send that info to kinman.chung@oracle.com. Thanks.
        Hide
        aosama added a comment -

        hi kim, i dropped u a note hope u got my email its aosama [at] gmail [dot] com

        Show
        aosama added a comment - hi kim, i dropped u a note hope u got my email its aosama [at] gmail [dot] com
        Hide
        kchung added a comment -

        Fixed in 4.0 and trunk.

        There are two parts to the fix.

        1. ResourceInjector will not be invoked for tag files.
        2. ResourceInjector.preDestroy is called for
        a. tags that extend SimpleTagSupport, and
        b. classic tag hanlder
        1. with tag pooling on (default), when the app exits
        2. with tag pooling off, at end tag

        i

        Show
        kchung added a comment - Fixed in 4.0 and trunk. There are two parts to the fix. 1. ResourceInjector will not be invoked for tag files. 2. ResourceInjector.preDestroy is called for a. tags that extend SimpleTagSupport, and b. classic tag hanlder 1. with tag pooling on (default), when the app exits 2. with tag pooling off, at end tag i
        Hide
        slominskir added a comment - - edited

        I can confirm the attached test case passes in 4.0, but if you add parameters to the tag a memory leak occurs. I've created a new issue: GLASSFISH-21083.

        Show
        slominskir added a comment - - edited I can confirm the attached test case passes in 4.0, but if you add parameters to the tag a memory leak occurs. I've created a new issue: GLASSFISH-21083 .

          People

          • Assignee:
            kchung
            Reporter:
            enrico_olivelli
          • Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: