Uploaded image for project: 'iBatis for Java [READ ONLY]'
  1. iBatis for Java [READ ONLY]
  2. IBATIS-721

PermGen leak on undeploy in Tomcat 6.x (ThreadLocal in ErrorContext)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 3.0 Beta 7
    • 3.0 Beta 8
    • Core
    • None
    • Java SE 1.6.0_17 (64 bit)
      Mac OS X 10.6.2
      Tomcat 6.0.20

    Description

      The current use of ThreadLocal in org.apache.ibatis.executor.ErrorContext can lead to permgen memory leaks on webapp undeploy on Tomcat 6.0.20

      The potential of a request thread being used as the ThreadLocal key without removal will pin the webapp class loader (and all loaded classes) in permgen memory after an undeploy.

      To reproduce:

      1) Deploy a webapp using ibatis 3.0 to tomcat
      2) Hit the webapp once with an execution path invoking ibatis
      3) Undeploy the webapp
      4) GC the tomcat process 2+ times to invoke a full GC (i.e. w/ jconsole or jvisualvm)
      5) dump the heap
      6) examine with jhat from later JDK 6 version

      (http://blogs.sun.com/fkieviet/entry/how_to_fix_the_dreaded)

      You should be able to see the webapp classes still loaded, by looking at the associated class loader and the reference chain from rootset you'll see a System class reference with the ErrorContext ThreadLocal instance chaining the class loader.

      I am using "-XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled" when launching tomcat.

      As a quick fix I was able to clean this up by adding LOCAL.remove() to ErrorContext.reset() on my local build. I don't know if this is a good long term solution...

      Attachments

        Activity

          People

            cbegin Clinton Begin
            tck Tom Kunicki
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: