You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2018/10/11 19:08:17 UTC

[9/9] activemq-artemis git commit: ARTEMIS-2108 Potential StackOverflowError when load balancing disabled

ARTEMIS-2108 Potential StackOverflowError when load balancing disabled

(cherry picked from commit d336a09f9a1c30362ec4421df9e9b1f494206175)


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/b6945b50
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/b6945b50
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/b6945b50

Branch: refs/heads/2.6.x
Commit: b6945b50fff7c21c9d3964f3dcd3187559bace0f
Parents: 70a70f4
Author: Justin Bertram <jb...@apache.org>
Authored: Wed Oct 3 19:18:27 2018 -0500
Committer: Clebert Suconic <cl...@apache.org>
Committed: Thu Oct 11 15:05:34 2018 -0400

----------------------------------------------------------------------
 .../core/postoffice/impl/BindingsImpl.java      | 20 ++++-
 .../RemoteBindingWithoutLoadBalancingTest.java  | 92 ++++++++++++++++++++
 2 files changed, 111 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b6945b50/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/BindingsImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/BindingsImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/BindingsImpl.java
index c669eba..c20e988 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/BindingsImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/BindingsImpl.java
@@ -408,11 +408,29 @@ public final class BindingsImpl implements Bindings {
       }
 
       if (messageLoadBalancingType.equals(MessageLoadBalancingType.OFF) && theBinding instanceof RemoteQueueBinding) {
-         theBinding = getNextBinding(message, routingName, bindings);
+         if (exclusivelyRemote(bindings)) {
+            theBinding = null;
+         } else {
+            theBinding = getNextBinding(message, routingName, bindings);
+         }
       }
+
       return theBinding;
    }
 
+   private boolean exclusivelyRemote(List<Binding> bindings) {
+      boolean result = true;
+
+      for (Binding binding : bindings) {
+         if (!(binding instanceof RemoteQueueBinding)) {
+            result = false;
+            break;
+         }
+      }
+
+      return result;
+   }
+
    private void routeUsingStrictOrdering(final Message message,
                                          final RoutingContext context,
                                          final GroupingHandler groupingGroupingHandler,

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b6945b50/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/distribution/RemoteBindingWithoutLoadBalancingTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/distribution/RemoteBindingWithoutLoadBalancingTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/distribution/RemoteBindingWithoutLoadBalancingTest.java
new file mode 100644
index 0000000..da06175
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/distribution/RemoteBindingWithoutLoadBalancingTest.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.tests.integration.cluster.distribution;
+
+import org.apache.activemq.artemis.core.server.cluster.impl.MessageLoadBalancingType;
+import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger;
+import org.junit.Before;
+import org.junit.Test;
+
+public class RemoteBindingWithoutLoadBalancingTest extends ClusterTestBase {
+
+   private static final IntegrationTestLogger log = IntegrationTestLogger.LOGGER;
+
+   @Override
+   @Before
+   public void setUp() throws Exception {
+      super.setUp();
+
+      setupServers();
+   }
+
+   protected boolean isNetty() {
+      return false;
+   }
+
+   /**
+    * It's possible that when a cluster has disabled message load balancing then a message
+    * sent to a node that only has a corresponding remote queue binding will trigger a
+    * stack overflow.
+    */
+   @Test
+   public void testStackOverflow() throws Exception {
+      setupCluster();
+
+      startServers();
+
+      setupSessionFactory(0, isNetty());
+      setupSessionFactory(1, isNetty());
+
+      createQueue(0, "queues.testaddress", "queue0", null, false);
+
+      waitForBindings(0, "queues.testaddress", 1, 0, true);
+
+      waitForBindings(1, "queues.testaddress", 1, 0, false);
+
+      send(1, "queues.testaddress", 1, false, null);
+   }
+
+   protected void setupCluster() throws Exception {
+      setupClusterConnection("cluster0", "queues", MessageLoadBalancingType.OFF, 1, isNetty(), 0, 1);
+
+      setupClusterConnection("cluster1", "queues", MessageLoadBalancingType.OFF, 1, isNetty(), 1, 0);
+   }
+
+   protected void setupServers() throws Exception {
+      setupServer(0, isFileStorage(), isNetty());
+      setupServer(1, isFileStorage(), isNetty());
+   }
+
+   protected void startServers() throws Exception {
+      startServers(0, 1);
+   }
+
+   protected void stopServers() throws Exception {
+      closeAllConsumers();
+
+      closeAllSessionFactories();
+
+      closeAllServerLocatorsFactories();
+
+      stopServers(0, 1);
+   }
+
+   @Override
+   protected boolean isFileStorage() {
+      return false;
+   }
+}