Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-4613

ThreadLocalsManager not cleaned up after pageDefinition transactions

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 9.0.1.2
    • Fix Version/s: 9.5.0
    • Component/s: None
    • Security Level: Jimmy
    • Labels:

      Description

      Reproducing procedure

      Download tomcat (reproduced on 8.5.56)

      In [tomcat root]/conf/tomcat-users.xml, create an admin with access to the manager panel:

      <user username="admin" password="admin" roles="manager-gui"/>

      (this allow to start and stop individual webapps, without a server restart)

      Deploy a ZK webapp as a war file (reproduced with a new project created from maven archetype ZK EE webapp)

      Run the server

      Open the application's zul page (a client must have connected in order to trigger the issue)

      Open the server's webapps manager (http://localhost:8080/manager/html)

      use the "stop" button in the application list to stop the ZK webapp

      Check server logs / console ([tomcat root]/catalina*.out)

      Current Result

      https://github.com/zkoss/zk/blob/dac625faf8c3eb18590c3bdd67e838d57d9418df/zk/src/org/zkoss/zk/ui/http/DHtmlLayoutServlet.java#L216

      https://github.com/zkoss/zk/blob/172c68a67e9cb9ee87de354b38e9a9baafc30c8f/zk/src/org/zkoss/zk/ui/metainfo/Parser.java#L218

       

      During DHTML Layout servlet operation, ThreadLocalsManager is used to store the pageDefinition in a threadlocal, but it's not cleaned up at the end of the transaction.

      This cause a minor memory overhead, and trigger messages in tomcat such as:

      lMapForLeaks The web application [zkdemo] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@35d75a7]) and a value of type [org.zkoss.zk.ui.metainfo.PageDefinition] (value [[PageDefinition: zkDemoContent, path=/WEB-INF/template/template_widget_demo.zul]]) 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.
      

      Expected Result

      Unused threadLocal objects should be released after the pageDefinition is no longer needed as a threadLocal value at the end of the page request.

      Debug Information

       

      Workaround

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rudyhuang rudyhuang
              Reporter:
              MDuchemin MDuchemin
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - 1 day Original Estimate - 1 day
                  1d
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 day, 1 hour
                  1d 1h