glassfish
  1. glassfish
  2. GLASSFISH-16712

Classloading issue when accessing class for the first time during JPA shutdown

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.1
    • Fix Version/s: 3.1.2_b11, 4.0
    • Component/s: deployment
    • Labels:
      None
    • Environment:

      Windows 7 Professional 64-bit, JDK 1.6.0 u24, Glassfish 3.1 b43

      Description

      Reference original forum thread here: http://www.java.net/forum/topic/glassfish/glassfish/classloading-issue-when-accessing-class-first-time-during-jpa-shutdown-glassfish-31

      To recap, Hibernate (and Ehcache) have relatively complex shutdown routines that sometimes result in the accessing of classes that have not yet been loaded. However, the class loader for the application is already stopped by the time these routines are called, which causes an IllegalStateException to be thrown.

      A test case is attached (a stripped down version of the one in the forum thread). Deploying and undeploying yields this stack trace (note that the following JVM flag needs to be added to the domain configuration to avoid an NPE caused by logging in the shutdown routine: -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false):

      org.hibernate.HibernateException: could not destruct listeners
      at org.hibernate.event.EventListeners.destroyListeners(EventListeners.java:226)
      at org.hibernate.impl.SessionFactoryImpl.close(SessionFactoryImpl.java:972)
      at org.hibernate.ejb.EntityManagerFactoryImpl.close(EntityManagerFactoryImpl.java:127)
      at org.glassfish.persistence.jpa.JPADeployer.closeEMFs(JPADeployer.java:404)
      at org.glassfish.persistence.jpa.JPADeployer.event(JPADeployer.java:395)
      at org.glassfish.kernel.event.EventsImpl$1.run(EventsImpl.java:120)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
      at java.util.concurrent.FutureTask.run(FutureTask.java:138)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:662)
      Caused by: java.lang.IllegalStateException: WEB9031: WebappClassLoader unable to load resource [org.hibernate.event.EventListeners$2], because it has not yet been started, or was already stopped
      at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1410)
      at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1368)
      at org.hibernate.event.EventListeners.destroyListeners(EventListeners.java:215)
      ... 11 more

        Activity

        atomicknight created issue -
        Hide
        Hong Zhang added a comment -

        As Mitesh replied in the forum thread, it's a little unusual to load classes during EMF clean up in undeploy, however we should try to accommodate this case.

        Show
        Hong Zhang added a comment - As Mitesh replied in the forum thread, it's a little unusual to load classes during EMF clean up in undeploy, however we should try to accommodate this case.
        Hong Zhang made changes -
        Field Original Value New Value
        Fix Version/s 3.2 [ 10969 ]
        Tags 3_1_1-scrubbed
        Hide
        slominskir added a comment - - edited

        I'm using Hibernate, but not using EhCache. So it would seem just including Hibernate 3.6 in your web application deployed on GlassFish 3.1 is enough to trigger this Exception. Since this causes a memory leak this is a big problem (must restart server after a few re-deploys). Also, the problem appears to be a regression - I didn't encounter it in GlassFish 3.0.1, but when I upgraded to 3.1 I started to see it. This is discussed further here: http://www.java.net/forum/topic/glassfish/glassfish/undeploy-exception-upgrading-glassfish-301-31

        Show
        slominskir added a comment - - edited I'm using Hibernate, but not using EhCache. So it would seem just including Hibernate 3.6 in your web application deployed on GlassFish 3.1 is enough to trigger this Exception. Since this causes a memory leak this is a big problem (must restart server after a few re-deploys). Also, the problem appears to be a regression - I didn't encounter it in GlassFish 3.0.1, but when I upgraded to 3.1 I started to see it. This is discussed further here: http://www.java.net/forum/topic/glassfish/glassfish/undeploy-exception-upgrading-glassfish-301-31
        Nazrul made changes -
        Tags 3_1_1-scrubbed 3_1_1-review 3_1_1-scrubbed
        Hide
        Nazrul added a comment -

        One other person ran into this issue while using Hibernate. It would be great if we can take a look at this.

        <slominskir>
        Something worth mentioning: I encountered a classloader issue in GlassFish 3.1 on undeploy that appears to be a regression from GlassFish 3.0.1: http://www.java.net/forum/topic/glassfish/glassfish/undeploy-exception-upgrading-glassfish-301-31
        </slominskir>

        Show
        Nazrul added a comment - One other person ran into this issue while using Hibernate. It would be great if we can take a look at this. <slominskir> Something worth mentioning: I encountered a classloader issue in GlassFish 3.1 on undeploy that appears to be a regression from GlassFish 3.0.1: http://www.java.net/forum/topic/glassfish/glassfish/undeploy-exception-upgrading-glassfish-301-31 </slominskir>
        scatari made changes -
        Tags 3_1_1-review 3_1_1-scrubbed 3_1_1-scrubbed
        scatari made changes -
        Tags 3_1_1-scrubbed 3_1-next 3_1_1-scrubbed
        Hide
        scatari added a comment -

        Marking it as to be considered after 3.1.1.

        Show
        scatari added a comment - Marking it as to be considered after 3.1.1.
        Hide
        scatari added a comment -

        Please evaluate this as for possible inclusion into 3.1.2.

        Show
        scatari added a comment - Please evaluate this as for possible inclusion into 3.1.2.
        scatari made changes -
        Tags 3_1-next 3_1_1-scrubbed 3_1-next 3_1_1-scrubbed 3_1_2-review
        Hide
        Hong Zhang added a comment -

        Move the classloader clean up from unload phase to clean phase so EMF clean up which happens before could use the classloader if needed. Changes checked in both trunk and 3.1.2 branch.

        Show
        Hong Zhang added a comment - Move the classloader clean up from unload phase to clean phase so EMF clean up which happens before could use the classloader if needed. Changes checked in both trunk and 3.1.2 branch.
        Hong Zhang made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 3.1.2_b11 [ 15325 ]
        Fix Version/s 4.0 [ 10970 ]
        Fix Version/s 3.2 [ 10969 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Hong Zhang
            Reporter:
            atomicknight
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: