grizzly
  1. grizzly
  2. GRIZZLY-1323

GenericGrizzlyListener.stop() throws NPE

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.3
    • Fix Version/s: 2.3, 3.0
    • Component/s: configuration
    • Labels:
      None
    • Environment:

      Grizzly 2.3-beta2 bundled with GlassFish 4.0

      Description

      When invoking GenericGrizzlyListener.stop(), it throws NPE for the transport object is null. The stack trace is:

      java.lang.NullPointerException
      at org.glassfish.grizzly.config.GenericGrizzlyListener.stop(GenericGrizzlyListener.java:169)
      at com.sun.enterprise.v3.services.impl.GrizzlyProxy.stop(GrizzlyProxy.java:150)
      at com.sun.enterprise.v3.services.impl.GrizzlyService.removeNetworkProxy(GrizzlyService.java:180)
      at com.sun.enterprise.v3.services.impl.GrizzlyService.removeNetworkProxy(GrizzlyService.java:169)
      at com.sun.enterprise.connectors.jms.system.ActiveJmsResourceAdapter.destroy(ActiveJmsResourceAdapter.java:385)
      at com.sun.enterprise.connectors.service.ResourceAdapterAdminServiceImpl$RAShutdownTask.run(ResourceAdapterAdminServiceImpl.java:624)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      at java.util.concurrent.FutureTask.run(FutureTask.java:166)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      at java.lang.Thread.run(Thread.java:722)

      ************************************************
      How to reproduce:
      ************************************************
      Install GlassFish 4.0
      asadmin start-domain domain1
      asadmin jms-ping --target server
      asadmin stop-domain domain1

      Then there is NPE in the server.log,

      I see this error in the server log when the domain is stopped:

      [#|2012-08-29T17:52:39.166+0100|WARNING|44.0|javax.enterprise.resource.resourceadapter.com.sun.enterprise.connectors.service|_ThreadID=83;_ThreadName=Thread-18;|RAR8053:
      RA [ jmsra ] stop failed, java.util.concurrent.ExecutionException: java.lang.NullPointerException|#]

      [#|2012-08-29T17:52:39.166+0100|INFO|44.0|javax.enterprise.resource.resourceadapter.com.sun.enterprise.connectors.service|_ThreadID=83;_ThreadName=Thread-18;|shutdown
      of RA [ jmsra ] is either already complete or already cancelled|#]

      [#|2012-08-29T17:52:39.166+0100|WARNING|44.0|javax.enterprise.resource.resourceadapter.com.sun.enterprise.connectors.service|_ThreadID=83;_ThreadName=Thread-18;|RAR7095:
      jmsra shutdown unsuccessful. Please refer the server and/or resource adapter logs for more information.|#]

      ************************************************
      Analysis:
      ************************************************
      In class GenericGrizzlyListener, line 169 throws NPE for transport is null. Can null checking be added before doing transport.stop() to avoid NPE?

      public void stop()
      throws IOException

      { stopDelayedExecutor(); transport.stop(); <-- line 169 transport = null; rootFilterChain = null; }

      Suggested fix:

      public void stop()
      throws IOException
      {
      stopDelayedExecutor();
      if (transport != null)

      { transport.stop(); transport = null; }

      rootFilterChain = null;
      }

        Activity

        Hide
        Ryan Lubke added a comment -

        Actually, it appears that this listener is being shutdown twice.

        The first time (where transport is not null), the call stack looks like:

        First Shutdown

        Thread-16@20 daemon, prio=5, in group 'main', status: 'RUNNING'
        at org.glassfish.grizzly.config.GenericGrizzlyListener.stop(GenericGrizzlyListener.java:169)
        at com.sun.enterprise.v3.services.impl.GrizzlyProxy.stop(GrizzlyProxy.java:150)
        at com.sun.enterprise.v3.services.impl.GrizzlyService.preDestroy(GrizzlyService.java:532)
        at org.jvnet.hk2.internal.ClazzCreator.preDestroyMe(ClazzCreator.java:263)
        at org.jvnet.hk2.internal.ClazzCreator.dispose(ClazzCreator.java:314)
        at org.jvnet.hk2.internal.SystemDescriptor.dispose(SystemDescriptor.java:441)
        at com.sun.enterprise.v3.server.RunLevelBridge.preDestroy(RunLevelBridge.java:122)
        at com.sun.enterprise.v3.server.StartupRunLevelBridge.preDestroy(StartupRunLevelBridge.java:65)
        at org.jvnet.hk2.internal.ClazzCreator.preDestroyMe(ClazzCreator.java:263)
        at org.jvnet.hk2.internal.ClazzCreator.dispose(ClazzCreator.java:314)
        at org.jvnet.hk2.internal.SystemDescriptor.dispose(SystemDescriptor.java:441)
        at org.glassfish.hk2.runlevel.internal.RunLevelContext.deactivate(RunLevelContext.java:165)
        at org.glassfish.hk2.runlevel.utilities.RunLevelControllerImpl.deactivate(RunLevelControllerImpl.java:371)
        at com.sun.enterprise.v3.server.AppServerStartup$AppServerActivator.deactivate(AppServerStartup.java:411)
        at org.glassfish.hk2.runlevel.utilities.RunLevelControllerImpl$Worker.deactivateRunLevel(RunLevelControllerImpl.java:864)
        at org.glassfish.hk2.runlevel.utilities.RunLevelControllerImpl$Worker.downActiveRecorder(RunLevelControllerImpl.java:757)
        at org.glassfish.hk2.runlevel.utilities.RunLevelControllerImpl$Worker.down(RunLevelControllerImpl.java:773)
        at org.glassfish.hk2.runlevel.utilities.RunLevelControllerImpl$Worker.run(RunLevelControllerImpl.java:687)
        at org.glassfish.hk2.runlevel.utilities.RunLevelControllerImpl$SyncProceedToWorker.proceedTo(RunLevelControllerImpl.java:948)
        at org.glassfish.hk2.runlevel.utilities.RunLevelControllerImpl.proceedTo(RunLevelControllerImpl.java:565)
        at org.glassfish.hk2.runlevel.utilities.RunLevelControllerImpl.proceedTo(RunLevelControllerImpl.java:349)
        at com.sun.enterprise.v3.server.AppServerStartup.proceedTo(AppServerStartup.java:364)
        at com.sun.enterprise.v3.server.AppServerStartup.stop(AppServerStartup.java:323)
        at com.sun.enterprise.glassfish.bootstrap.GlassFishImpl.stop(GlassFishImpl.java:88)
        at com.sun.enterprise.glassfish.bootstrap.GlassFishDecorator.stop(GlassFishDecorator.java:68)
        at com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishImpl.stop(EmbeddedOSGiGlassFishImpl.java:80)
        at com.sun.enterprise.v3.admin.StopServer.doExecute(StopServer.java:78)
        at com.sun.enterprise.v3.admin.StopDomainCommand.execute(StopDomainCommand.java:95)
        at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:513)
        at org.glassfish.api.AsyncImpl$1$1.run(AsyncImpl.java:79)

        and then the second call is here:

        Second Shutdown Call

        Thread-18@1175 daemon, prio=5, in group 'main', status: 'RUNNING'
        at org.glassfish.grizzly.config.GenericGrizzlyListener.stop(GenericGrizzlyListener.java:169)
        at com.sun.enterprise.v3.services.impl.GrizzlyProxy.stop(GrizzlyProxy.java:150)
        at com.sun.enterprise.v3.services.impl.GrizzlyService.removeNetworkProxy(GrizzlyService.java:180)
        at com.sun.enterprise.v3.services.impl.GrizzlyService.removeNetworkProxy(GrizzlyService.java:169)
        at com.sun.enterprise.connectors.jms.system.ActiveJmsResourceAdapter.destroy(ActiveJmsResourceAdapter.java:385)
        at com.sun.enterprise.connectors.service.ResourceAdapterAdminServiceImpl$RAShutdownTask.run(ResourceAdapterAdminServiceImpl.java:624)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)

        So, given this, I don't believe this is a Grizzly issue. It may be worth taking this up with the JMS and HK2 teams however.

        Show
        Ryan Lubke added a comment - Actually, it appears that this listener is being shutdown twice. The first time (where transport is not null), the call stack looks like: First Shutdown Thread-16@20 daemon, prio=5, in group 'main', status: 'RUNNING' at org.glassfish.grizzly.config.GenericGrizzlyListener.stop(GenericGrizzlyListener.java:169) at com.sun.enterprise.v3.services.impl.GrizzlyProxy.stop(GrizzlyProxy.java:150) at com.sun.enterprise.v3.services.impl.GrizzlyService.preDestroy(GrizzlyService.java:532) at org.jvnet.hk2.internal.ClazzCreator.preDestroyMe(ClazzCreator.java:263) at org.jvnet.hk2.internal.ClazzCreator.dispose(ClazzCreator.java:314) at org.jvnet.hk2.internal.SystemDescriptor.dispose(SystemDescriptor.java:441) at com.sun.enterprise.v3.server.RunLevelBridge.preDestroy(RunLevelBridge.java:122) at com.sun.enterprise.v3.server.StartupRunLevelBridge.preDestroy(StartupRunLevelBridge.java:65) at org.jvnet.hk2.internal.ClazzCreator.preDestroyMe(ClazzCreator.java:263) at org.jvnet.hk2.internal.ClazzCreator.dispose(ClazzCreator.java:314) at org.jvnet.hk2.internal.SystemDescriptor.dispose(SystemDescriptor.java:441) at org.glassfish.hk2.runlevel.internal.RunLevelContext.deactivate(RunLevelContext.java:165) at org.glassfish.hk2.runlevel.utilities.RunLevelControllerImpl.deactivate(RunLevelControllerImpl.java:371) at com.sun.enterprise.v3.server.AppServerStartup$AppServerActivator.deactivate(AppServerStartup.java:411) at org.glassfish.hk2.runlevel.utilities.RunLevelControllerImpl$Worker.deactivateRunLevel(RunLevelControllerImpl.java:864) at org.glassfish.hk2.runlevel.utilities.RunLevelControllerImpl$Worker.downActiveRecorder(RunLevelControllerImpl.java:757) at org.glassfish.hk2.runlevel.utilities.RunLevelControllerImpl$Worker.down(RunLevelControllerImpl.java:773) at org.glassfish.hk2.runlevel.utilities.RunLevelControllerImpl$Worker.run(RunLevelControllerImpl.java:687) at org.glassfish.hk2.runlevel.utilities.RunLevelControllerImpl$SyncProceedToWorker.proceedTo(RunLevelControllerImpl.java:948) at org.glassfish.hk2.runlevel.utilities.RunLevelControllerImpl.proceedTo(RunLevelControllerImpl.java:565) at org.glassfish.hk2.runlevel.utilities.RunLevelControllerImpl.proceedTo(RunLevelControllerImpl.java:349) at com.sun.enterprise.v3.server.AppServerStartup.proceedTo(AppServerStartup.java:364) at com.sun.enterprise.v3.server.AppServerStartup.stop(AppServerStartup.java:323) at com.sun.enterprise.glassfish.bootstrap.GlassFishImpl.stop(GlassFishImpl.java:88) at com.sun.enterprise.glassfish.bootstrap.GlassFishDecorator.stop(GlassFishDecorator.java:68) at com.sun.enterprise.glassfish.bootstrap.osgi.EmbeddedOSGiGlassFishImpl.stop(EmbeddedOSGiGlassFishImpl.java:80) at com.sun.enterprise.v3.admin.StopServer.doExecute(StopServer.java:78) at com.sun.enterprise.v3.admin.StopDomainCommand.execute(StopDomainCommand.java:95) at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:513) at org.glassfish.api.AsyncImpl$1$1.run(AsyncImpl.java:79) and then the second call is here: Second Shutdown Call Thread-18@1175 daemon, prio=5, in group 'main', status: 'RUNNING' at org.glassfish.grizzly.config.GenericGrizzlyListener.stop(GenericGrizzlyListener.java:169) at com.sun.enterprise.v3.services.impl.GrizzlyProxy.stop(GrizzlyProxy.java:150) at com.sun.enterprise.v3.services.impl.GrizzlyService.removeNetworkProxy(GrizzlyService.java:180) at com.sun.enterprise.v3.services.impl.GrizzlyService.removeNetworkProxy(GrizzlyService.java:169) at com.sun.enterprise.connectors.jms.system.ActiveJmsResourceAdapter.destroy(ActiveJmsResourceAdapter.java:385) at com.sun.enterprise.connectors.service.ResourceAdapterAdminServiceImpl$RAShutdownTask.run(ResourceAdapterAdminServiceImpl.java:624) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) So, given this, I don't believe this is a Grizzly issue. It may be worth taking this up with the JMS and HK2 teams however.
        Hide
        Ryan Lubke added a comment -

        Closing per my last comment.

        Show
        Ryan Lubke added a comment - Closing per my last comment.
        Hide
        David Zhao added a comment -

        Thanks Ryan for your analysis.

        Yes, there are 2 calls on GenericGrizzlyListener.stop() as you pointed out. But I think anyway NPE is not good even for the second call. Can you think of enhancing it to be "A call to stop on a listener that has already been stopped is ignored", which could be more user friendly? Or at least throw another custom exception instead of NPE.

        Show
        David Zhao added a comment - Thanks Ryan for your analysis. Yes, there are 2 calls on GenericGrizzlyListener.stop() as you pointed out. But I think anyway NPE is not good even for the second call. Can you think of enhancing it to be "A call to stop on a listener that has already been stopped is ignored", which could be more user friendly? Or at least throw another custom exception instead of NPE.
        Hide
        Ryan Lubke added a comment -

        We can look into it, but I think it's important to resolve the root cause.

        Show
        Ryan Lubke added a comment - We can look into it, but I think it's important to resolve the root cause.
        Hide
        Ryan Lubke added a comment -

        Changes applied:

        2.3.x: 36d0aa1573218f173ac4a731920e922d35e869d7
        master: 1c7f4d3efdc0d8bcf6fdfc8827f0d4ef7361ef11

        Show
        Ryan Lubke added a comment - Changes applied: 2.3.x: 36d0aa1573218f173ac4a731920e922d35e869d7 master: 1c7f4d3efdc0d8bcf6fdfc8827f0d4ef7361ef11

          People

          • Assignee:
            Ryan Lubke
            Reporter:
            David Zhao
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: