4 Replies Latest reply on Apr 7, 2008 2:47 PM by brian.stansberry

    JBAS-5376: leak of webapp classloader when deployed in ear

    brian.stansberry

      Discussion of http://jira.jboss.com/jira/browse/JBAS-5376.

      I've walked through the deploy/undeploy of an ear with an embedded war, and here's what I see. During deployment of the nested war:

      AbstractLevelClassLoaderSystemDeployer.createClassLoader(DeploymentUnit) -->
      VFSDeploymentClassLoaderPolicyModule.registerClassLoaderPolicy(ClassLoaderSystem system, ClassLoader parent) -->
      DefaultClassLoaderSystem.registerClassLoaderPolicy(String domainName, ParentPolicy parentPolicy, Loader parent, ClassLoaderPolicy policy) -->
      ClassLoaderSystem.createAndRegisterDomain(String name, ParentPolicy parentPolicy, Loader parent)

      Here we create a domain for the war and assign param "Loader parent" to the new domain as it's parent. "Loader parent" has a ref to the ear classloader. We then register the new domain with the classloader system. This sets up the chain of references shown in the JIRA description.

      During undeploy:

      AbstractLevelClassLoaderSystemDeployer.removeClassLoader(DeploymentUnit unit) -->
      BaseClassLoaderSystem.unregisterClassLoader(ClassLoader classLoader) -->
      BaseClassLoaderSystem.unregisterClassLoaderPolicy(ClassLoaderPolicy policy)

      that removes the ref to the *war's* poliyc/classloader from the war's domain, But the war domain itself is never unregistered from the ClassLoaderSystem. So the ref to the parent is leaked.

      In an eclipse I don't see any calls at all to ClassLoaderSystem.unregisterDomain(ClassLoaderDomain domain) anywhere. ClassLoaderSystem.shutdown() removes all domains, but that doesn't help here.

        • 1. Re: JBAS-5376: leak of webapp classloader when deployed in e
          brian.stansberry

          LOL. Adrian looking at JBAS-5368 found the exact same thing, and doesn't appear to need my details. :-)

          • 2. Re: JBAS-5376: leak of webapp classloader when deployed in e

            The patch is fairly simple (see the change to undeploy below).
            If you can't wait for the next release of jboss-deployers
            then we could just copy the fixed deployer into the AS project as a temporary fix.

            Index: deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractLevelClassLoaderSystemDeployer.java
            ===================================================================
            --- deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractLevelClassLoaderSystemDeployer.java (revision 71766)
            +++ deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractLevelClassLoaderSystemDeployer.java (working copy)
            @@ -21,6 +21,7 @@
             */
             package org.jboss.deployers.plugins.classloading;
            
            +import org.jboss.classloader.spi.ClassLoaderDomain;
             import org.jboss.classloader.spi.ClassLoaderSystem;
             import org.jboss.classloading.spi.dependency.ClassLoading;
             import org.jboss.classloading.spi.dependency.Module;
            @@ -136,8 +137,22 @@
             ClassLoader classLoader = unit.getClassLoader();
             try
             {
            - // Remove the classloader
            - system.unregisterClassLoader(classLoader);
            + try
            + {
            + // Remove the classloader
            + system.unregisterClassLoader(classLoader);
            + }
            + finally
            + {
            + // Try to tidy up empty domains
            + String domainName = module.getDeterminedDomainName();
            + if (ClassLoaderSystem.DEFAULT_DOMAIN_NAME.equals(domainName) == false)
            + {
            + ClassLoaderDomain domain = system.getDomain(domainName);
            + if (domain.hasClassLoaders() == false)
            + system.unregisterDomain(domain);
            + }
            + }
             }
             finally
             {
            


            • 3. Re: JBAS-5376: leak of webapp classloader when deployed in e
              brian.stansberry

              I'll let you know. Urgent thing for me is I'm trying to sort out classloading related failures in the FIELD granularity web session replication tests; first step was analyzing ClassLoaderLeakUnitTestCase failures, which is what led to my filing the JIRA. But this ear issue was really a tangent; the FIELD tests don't even use an ear.

              The FIELD tests just use a war, but it declares a loader-repository. I'll see if it could somehow be related and post back one way or another.

              • 4. Re: JBAS-5376: leak of webapp classloader when deployed in e
                brian.stansberry

                If you deploy a war with a loader-repository configured, the domain gets leaked; your patch above will fix that. But, in this case it's not such a big deal, as the war's classloader gets removed from the leaked domain, and the leaked domain's parent is the default domain. So, my FIELD granularity classloader leak problem is something else.