4 Replies Latest reply on Apr 1, 2012 3:24 AM by typek_pb

    Jboss AOP classloading bug

    ud1

      I'm using JBoss 6.0.0 with AOP for logging user actions and function call durations. Functions of interest are marked by our custom @Trace annotation and there is an our tracing aspect, that do all the work. But sometimes, probably after jboss restart, some random functionality of the project becomes unavailable, e.g. some dropdown lists didn't working or some buttons pressing do nothing. After second rebooting everething work fine. I can't reproduce this on my machine, but customers regulary (once or twice a month) reporting about the problem. Here is the typical log with org.jboss.classpool logging on:

       

      http://pastebin.com/f4TEduCB

       

      When all is functioning properly the log look's like:

       

      http://pastebin.com/zZKPk643

       

      I have made some investigation and degugging, so probably I have found the cause of the problem.

      At first, if you look at ClassPoolToDomainAdapter with a lot of byte array class paths in it, you could see the difference, at normal working this list

      contains BaseClassLoader@xxxxxx{vfs:///D:/retailHub/loan/server/default/deploy/myProject.ear} ClassPath at the end, but then the problem is it doesn't.

      After deepest code investigation I figured out, that this could happen then something call close() on а ClassPool, and this probably happens inside unregisterClassLoader() function.

      During joint point constraction Aspect Manager calls several times unregisterClassLoader() function:

       

      ClassPoolRepository

         public void unregisterClassLoader(ClassLoader classLoader)

         {

            registryHandler.unregisterClassLoader(classLoader); // <-- calls JBossClRegistryHandler.unregisterClassLoader()

            if (callbacks != null && callbacks.size() > 0)

            {

               for (ClassPoolRepositoryCallback callback : callbacks)

               {

                  callback.classLoaderUnregistered(classLoader);

               }

            }

         }

       

      which in turn calls JBossClRegistryHandler.registerClassLoader() functions with possible result of a closing the class pool.

       

      JBossClRegistryHandler

         public ClassPool registerClassLoader(ClassLoader classLoader)

         {

            ScopedClassPool classPool = (ScopedClassPool) successor.registerClassLoader(classLoader);

            if (classPool == null) // <-- true

            {

               // TODO check this works; was delegate before

               successor.unregisterClassLoader(classLoader); // <-- calls classLoader.close()

            }

            else

            {

               Module module = getModuleForClassLoader(classLoader);

               this.registeredModules.put(module, classPool);

            }

            return classPool;

         }

       

      I can't understand what is the purpose of the DefaultClassLoaderRegistryHandler, but it can return null from registerClassLoader() function,

      probaly then several jointpoints are generated concurrently from different threads:

       

      ClassPoolRepository$DefaultClassLoaderRegistryHandler

            public ClassPool registerClassLoader(ClassLoader classLoader)

            {

               if (classLoader == null)

               {

                  classLoader = SecurityActions.getContextClassLoader();

               }

       

               if (currentClassLoaders.putIfAbsent(classLoader, Boolean.TRUE) != null)

               {

                  return null; // <-- Returns null

               }

       

               ScopedClassPool classPool = (ScopedClassPool) ClassPoolRepository.super.registerClassLoader(classLoader);

               currentClassLoaders.remove(classLoader);

               return classPool;

            }

       

      ScopedClassPoolRepositoryImpl:

         public void unregisterClassLoader(ClassLoader cl) {

            synchronized (registeredCLs) {

               ScopedClassPool pool = registeredCLs.remove(cl);

               if (pool != null)

                  pool.close(); // <-- close

            }

         }

       

      ScopedClassPool:

         public void close() {

            this.removeClassPath(classPath); // <-- remove BaseClassLoader@xxxxxx{vfs:///D:/retailHub/loan/server/default/deploy/myProject.ear} classpath

            classPath.close();

            classes.clear();

            softcache.clear();

         }

       

      During joint point creation the myProject.war class loader is used, it redirects calls to JBossClClassPoolDomain, and in turn to SuperClassesFirstWeavingStrategy, and finally

      the reference to the old ClassPool (with a lot of byte array class paths) is used. Is has no myProject.ear ClassLoader any more, so NotFoundException is fired.

       

      I don't know how to fix this, I will appreciate your help.

        • 1. Re: Jboss AOP classloading bug
          goldm

          Hi,

           

          it seems I have a similar problem, have you found some workaround for this bug?

          • 2. Re: Jboss AOP classloading bug
            ud1

            I simply sinchronized calls of registerClassLoader():

            I have created class:

             

             

             

            package myapp.aop;

             

            import javassist.ClassPool;

             

            import org.jboss.classpool.plugins.jbosscl.JBossClClassPoolConfig;

            import org.jboss.classpool.plugins.jbosscl.JBossClDelegatingClassPoolFactory;

            import org.jboss.classpool.spi.ClassLoaderRegistryHandler;

            import org.jboss.classpool.spi.ClassPoolRepository;

             

            import org.jboss.logging.Logger;

             

            public class ClassPoolFactory extends JBossClDelegatingClassPoolFactory

            {

            private final Logger log = Logger.getLogger(ClassPoolFactory.class);

             

            private class Handler implements ClassLoaderRegistryHandler

            {

            private ClassLoaderRegistryHandler successor;

             

            public ClassPool registerClassLoader(ClassLoader classLoader)

            {

            ClassPool result;

            synchronized(successor)

            {

            result = successor.registerClassLoader(classLoader);

            }

             

            if (result == null)

            log.debug("registerClassLoader() returned null, " + classLoader);

             

            return result;

            }

             

            public void unregisterClassLoader(ClassLoader classLoader)

            {

            successor.unregisterClassLoader(classLoader);

            }

             

            public void setSuccessor(ClassLoaderRegistryHandler handler)

            {

            successor = handler;

            }

            }

             

            public ClassPoolFactory(JBossClClassPoolConfig config)

            {

            super(config.getDomainRegistry(), config.getRegisterModuleCallback());

            config.setClassPoolFactory(this);

            ClassPoolRepository.getInstance().setClassPoolFactory(this);

            }

             

            public ClassLoaderRegistryHandler create(ClassLoaderRegistryHandler successor)

            {

            ClassLoaderRegistryHandler handler = new Handler();

            handler.setSuccessor(super.create(successor));

            return handler;

            }

            }

             

            and added these lines to the aop.xml file:

             

            ...

               <classloader name="aop-classloader" xmlns="urn:jboss:classloader:1.0" export-all="NON_EMPTY" import-all="true">

                  ...

                  <root>${jboss.server.home.url}/lib/myapp-aop.jar</root>

               </classloader>

             

            ...

               <bean name="MyAppClassPoolFactory" class="myapp.ClassPoolFactory">

                  <constructor>

                     <parameter>

                        <inject bean="JBossClClassPoolConfig"/>

                     </parameter>

                  </constructor>

               </bean>

             

            ...

             

             

             

            Probably it should work.

            • 3. Re: Jboss AOP classloading bug
              goldm

              Thank you for quick response, I have tried it, did multiple JBoss restarts and problem didn't occured, great, you're my saviour :-)

              • 4. Re: Jboss AOP classloading bug
                typek_pb

                sounds like there should be bug filled to make sure it can be fixed upstream.

                Any volunteer?