QPID-8212: Throw exception only when session is not closing
authorAlex Rudyy <orudyy@apache.org>
Wed, 11 Jul 2018 22:10:51 +0000 (23:10 +0100)
committerAlex Rudyy <orudyy@apache.org>
Fri, 13 Jul 2018 09:11:45 +0000 (10:11 +0100)
client/src/main/java/org/apache/qpid/client/protocol/AMQProtocolSession.java

index 13c122f..bce7845 100644 (file)
@@ -480,15 +480,45 @@ public class AMQProtocolSession implements AMQVersionAwareProtocolSession
     }
 
     @Override
-    public void methodFrameReceived(final int channel, final AMQMethodBody amqMethodBody) throws QpidException
+    public void methodFrameReceived(final int channelId, final AMQMethodBody amqMethodBody) throws QpidException
     {
         try
         {
-            _protocolHandler.methodBodyReceived(channel, amqMethodBody);
+            _protocolHandler.methodBodyReceived(channelId, amqMethodBody);
         }
         catch (IllegalStateException e)
         {
-            throw new QpidException("Unexpected exception on receiving method " + amqMethodBody, e);
+            AMQSession session = _connection.getSession(channelId);
+            if (session == null)
+            {
+                if (isClosing(channelId))
+                {
+                    _logger.debug(
+                            "Ignoring incoming method {} of class {} on closing channel {}",
+                            amqMethodBody.getMethod(),
+                            amqMethodBody.getClazz(),
+                            channelId, e);
+                    _protocolHandler.propagateExceptionToMethodFrameListener(channelId,
+                                                                             amqMethodBody,
+                                                                             new QpidException("Session is closing", e));
+                }
+                else
+                {
+                    throw new QpidException(String.format(
+                            "Method '%d' of class '%d' is received on unknown channel '%d'",
+                            amqMethodBody.getMethod(),
+                            amqMethodBody.getClazz(),
+                            channelId));
+                }
+            }
+            else
+            {
+                throw new QpidException(String.format(
+                        "Unexpected exception on receiving method '%d' of class '%d' on channel '%d'",
+                        amqMethodBody.getMethod(),
+                        amqMethodBody.getClazz(),
+                        channelId), e);
+            }
         }
     }