7 Replies Latest reply on Apr 25, 2006 1:28 AM by Dean Fantham

    NPE when closing connection

    Janosch Machowinski Newbie

      Hey,
      I looked through the FAQ and the forum and didn't realy find an similar issue...

      On closing of the JMSConnection we sometimes get the following stacktrace (I will try to get a TRACE output of this):


      16:21:33,580 ERROR [SocketManager] Failed to handle: org.jboss.mq.il.uil2.msgs.CloseMsg32378465[msgType: m_connectionClosing, msgID: -2146749334, error: null]
      java.lang.NullPointerException
      at org.jboss.mq.server.JMSDestinationManager.connectionClosing(JMSDestinationManager.java:509)
      at org.jboss.mq.server.JMSServerInterceptorSupport.connectionClosing(JMSServerInterceptorSupport.java:128)
      at org.jboss.mq.security.ServerSecurityInterceptor.connectionClosing(ServerSecurityInterceptor.java:77)
      at org.jboss.mq.server.TracingInterceptor.connectionClosing(TracingInterceptor.java:193)
      at org.jboss.mq.server.JMSServerInvoker.connectionClosing(JMSServerInvoker.java:128)
      at org.jboss.mq.il.uil2.ServerSocketManagerHandler.handleMsg(ServerSocketManagerHandler.java:126)
      at org.jboss.mq.il.uil2.SocketManager$ReadTask.handleMsg(SocketManager.java:396)
      at org.jboss.mq.il.uil2.msgs.BaseMsg.run(BaseMsg.java:392)
      at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:748)
      at java.lang.Thread.run(Thread.java:534)


      We use the following code to close the connection :
      private static class ConnectionWrapper
       {
       public QueueConnection connection;
       public QueueSession session;
       public Queue currentReceiveQueue;
       }
      
       public void closeConnection(ConnectionWrapper con)
       {
       try
       {
       if (con.session != null)
       con.session.close();
       }
       catch (JMSException e)
       {
       LOG.error("Failed to close JMS session", e);
       }
      
       try
       {
       if (con.connection != null)
       con.connection.close();
       }
       catch (JMSException e)
       {
       LOG.error("Failed to close JMS Connection", e);
       }
      
       con.session = null;
       con.connection = null;
       }
      


      Any ideas ?


        • 1. Re: NPE when closing connection
          Janosch Machowinski Newbie

          I forgot to say, we use JBoss 3.2.8.SP1 on SuSe Linux 9.3 (32Bit)

          Okay, it took some hours, but now I have a TRACE trace ;-)


          2006-03-15 13:30:31,035 DEBUG [org.jboss.mq.il.uil2.SocketManager] End ReadTask.run
          2006-03-15 13:30:31,035 DEBUG [org.jboss.mq.il.uil2.SocketManager] End ReadTask.run
          2006-03-15 13:30:31,035 DEBUG [org.jboss.mq.il.uil2.UILClientILService] Stopping
          2006-03-15 13:30:31,038 DEBUG [org.jboss.mq.il.uil2.SocketManager] End WriteTask.run
          2006-03-15 13:30:31,052 ERROR [org.jboss.mq.il.uil2.SocketManager] Failed to handle: org.jboss.mq.il.uil2.msgs.CloseMsg13905452[msgType: m_connectionClosing,
          msgID: -2118850601, error: null]
          java.lang.NullPointerException
          at org.jboss.mq.server.JMSDestinationManager.connectionClosing(JMSDestinationManager.java:509)
          at org.jboss.mq.server.JMSServerInterceptorSupport.connectionClosing(JMSServerInterceptorSupport.java:128)
          at org.jboss.mq.security.ServerSecurityInterceptor.connectionClosing(ServerSecurityInterceptor.java:77)
          at org.jboss.mq.server.TracingInterceptor.connectionClosing(TracingInterceptor.java:193)
          at org.jboss.mq.server.JMSServerInvoker.connectionClosing(JMSServerInvoker.java:128)
          at org.jboss.mq.il.uil2.ServerSocketManagerHandler.handleMsg(ServerSocketManagerHandler.java:126)
          at org.jboss.mq.il.uil2.SocketManager$ReadTask.handleMsg(SocketManager.java:396)
          at org.jboss.mq.il.uil2.msgs.BaseMsg.run(BaseMsg.java:392)
          at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:748)
          at java.lang.Thread.run(Thread.java:534)
          2006-03-15 13:30:31,060 DEBUG [org.jboss.mq.il.uil2.UILClientILService] Stopping
          2006-03-15 13:30:31,062 DEBUG [org.jboss.mq.il.uil2.SocketManager] End WriteTask.run


          Could this be some weired concurrency problem ?

          While looking through the trace, I also noticed, that it is full of stacktraces like

          2006-03-15 13:30:31,195 DEBUG [org.jboss.mq.il.uil2.SocketManager] Failed to handle: org.jboss.mq.il.uil2.msgs.CloseMsg28257914[msgType: m_connectionClosing,
          msgID: -2118850538, error: null]
          java.io.IOException: Client is not connected
          at org.jboss.mq.il.uil2.SocketManager.internalSendMessage(SocketManager.java:265)
          at org.jboss.mq.il.uil2.SocketManager.sendReply(SocketManager.java:239)
          at org.jboss.mq.il.uil2.ServerSocketManagerHandler.handleMsg(ServerSocketManagerHandler.java:128)
          at org.jboss.mq.il.uil2.SocketManager$ReadTask.handleMsg(SocketManager.java:396)
          at org.jboss.mq.il.uil2.msgs.BaseMsg.run(BaseMsg.java:392)
          at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:748)
          at java.lang.Thread.run(Thread.java:534)

          is this normal ?
          Thanks

          • 2. Re: NPE when closing connection
            Adrian Brock Master

            I don't see how that is possible unless there is a bug in
            ConcurrentReaderHashMap.

            The message says you managed to get a null into the
            SpyDestinations->JMSDestinations map

            But ConcurrentReaderHashMap (which stores the map)
            doesn't accept null in either the key or the value.

             public void connectionClosing(ConnectionToken dc) throws JMSException
             {
             if (dc == null)
             return;
            
             // Close it's ClientConsumer
             ClientConsumer cq = (ClientConsumer) clientConsumers.remove(dc);
             if (cq != null)
             cq.close();
            
             //unregister its clientID
             if (dc.getClientID() != null)
             stateManager.removeLoggedOnClientId(dc.getClientID());
            
             //Remove any temporary destinations the consumer may have created.
             Iterator i = destinations.entrySet().iterator();
             while (i.hasNext())
             {
             Map.Entry entry = (Map.Entry) i.next();
             JMSDestination sq = (JMSDestination) entry.getValue();
             ClientConsumer cc = sq.temporaryDestination; // NPE HERE (line 509) - sq comes from value side of ConcurrentReaderHashMap!!!!
             if (cc != null && dc.equals(cc.connectionToken))
             {
             i.remove();
             deleteTemporaryDestination(dc, sq);
             }
             }
             // Close the clientIL
             try
             {
             if (dc.clientIL != null)
             dc.clientIL.close();
             }
             catch (Exception ex)
             {
             // We skipp warning, to often the client will allways
             // have gone when we get here
             //log.warn("Could not close clientIL: " +ex,ex);
             }
             }
            


            • 3. Re: NPE when closing connection
              Elias Ross Master

              Couldn't Map.Entry change between iteration and use? Looking at the class, it's certainly possible:

              Map m = new ConcurrentHashMap();
              m.put("foo", "bar");
              Iterator i = m.entrySet().iterator();
              Map.Entry me = i.next();
              m.removeKey("foo");
              me.getValue(); // returns null


              Not sure how getValue() should behave in these circumstances...

              Looking at the source to "remove:"
               public Object remove(Object key) {
               /*
               Find the entry, then
               1. Set value field to null, to force get() to retry
               2. Rebuild the list without this entry.
               All entries following removed node can stay in list, but
               all preceeding ones need to be cloned. Traversals rely
               on this strategy to ensure that elements will not be
               repeated during iteration.
               */
              


              Also, take a look at ConcurrentHashMap.putAll:

              public synchronized void putAll(Map t) {
               int n = t.size();
               if (n == 0)
               return;
              
               // Expand enough to hold at least n elements without resizing.
               // We can only resize table by factor of two at a time.
               // It is faster to rehash with fewer elements, so do it now.
               while (n >= threshold)
               rehash();
              
               for (Iterator it = t.entrySet().iterator(); it.hasNext();) {
               Map.Entry entry = (Map.Entry) it.next();
               Object key = entry.getKey();
               Object value = entry.getValue();
               put(key, value);
               }
               }


              Seems like doing a copy operation when a map is being concurrently modified might result in some NPEs.

              Do I get a cookie?

              • 5. Re: NPE when closing connection
                Scott Nieman Newbie

                I have seen this problem from 3.2.7 on.

                http://www.jboss.com/index.html?module=bb&op=viewtopic&t=78957

                So when is JBossAS-4.0.4.CR2 to be released? Can it be apply to 3.2.8 in a SP2????

                • 6. Re: NPE when closing connection
                  Scott Stark Master

                  When the 4.0.4.CR2 roadmap issues are resolved it will be released. There are no plans for a 3.2.8SP2 in the near future currently.

                  • 7. Re: NPE when closing connection
                    Dean Fantham Newbie

                     

                    "adrian@jboss.org" wrote:
                    Better than a cookie, a bug report:
                    http://jira.jboss.com/jira/browse/JBAS-2973


                    We are using Jboss 3.2.8 SP1 and are seeing these errors throughout the system when using JMS queues. Is there a workaround in the 3.2.8 system or something we can include into our beans to deal with this?