You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ro...@apache.org on 2024/07/15 14:34:26 UTC
(activemq-artemis) branch main updated: ARTEMIS-4919 Handle Exception from proton transport process
This is an automated email from the ASF dual-hosted git repository.
robbie pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
The following commit(s) were added to refs/heads/main by this push:
new 1361e29739 ARTEMIS-4919 Handle Exception from proton transport process
1361e29739 is described below
commit 1361e297392531b83c6d4137ce77883749cb48de
Author: Timothy Bish <ta...@gmail.com>
AuthorDate: Mon Jul 15 10:10:27 2024 -0400
ARTEMIS-4919 Handle Exception from proton transport process
Handle any exceptions from the proton transport and set the error on the
transport for processing in the events dispatch cycle by adding in handling
of the transport error event.
---
.../amqp/proton/AMQPConnectionContext.java | 10 ++
.../protocol/amqp/proton/handler/EventHandler.java | 3 +
.../protocol/amqp/proton/handler/Events.java | 3 +
.../amqp/proton/handler/ProtonHandler.java | 19 ++-
.../amqp/AMQPProtocolErrorHandlingTest.java | 180 +++++++++++++++++++++
5 files changed, 210 insertions(+), 5 deletions(-)
diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java
index b31d463433..7272d52555 100644
--- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java
+++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java
@@ -45,6 +45,7 @@ import org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederati
import org.apache.activemq.artemis.protocol.amqp.connect.federation.AMQPFederationQueueSenderController;
import org.apache.activemq.artemis.protocol.amqp.connect.mirror.AMQPMirrorControllerSource;
import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException;
+import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException;
import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPSecurityException;
import org.apache.activemq.artemis.protocol.amqp.logger.ActiveMQAMQPProtocolLogger;
import org.apache.activemq.artemis.protocol.amqp.logger.ActiveMQAMQPProtocolMessageBundle;
@@ -750,6 +751,15 @@ public class AMQPConnectionContext extends ProtonInitializable implements EventH
}
}
+ @Override
+ public void onTransportError(Transport transport) throws Exception {
+ final String errorMessage = transport.getCondition() != null && transport.getCondition().getDescription() != null ?
+ transport.getCondition().getDescription() : "Unknown Internal Error";
+
+ // Cleanup later after the any pending work gets sent to the remote via an IO flush.
+ runLater(() -> connectionCallback.getProtonConnectionDelegate().fail(new ActiveMQAMQPInternalErrorException(errorMessage)));
+ }
+
@Override
public void onRemoteClose(Connection connection) {
handler.requireHandler();
diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/EventHandler.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/EventHandler.java
index 1f2877a59d..4c4ac408ed 100644
--- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/EventHandler.java
+++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/EventHandler.java
@@ -110,6 +110,9 @@ public interface EventHandler {
default void onDelivery(Delivery delivery) throws Exception {
}
+ default void onTransportError(Transport transport) throws Exception {
+ }
+
default void onTransport(Transport transport) throws Exception {
}
diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/Events.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/Events.java
index a4d146396c..a0f2cb1afa 100644
--- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/Events.java
+++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/Events.java
@@ -85,6 +85,9 @@ public final class Events {
case LINK_REMOTE_DETACH:
handler.onRemoteDetach(event.getLink());
break;
+ case TRANSPORT_ERROR:
+ handler.onTransportError(event.getTransport());
+ break;
case TRANSPORT:
handler.onTransport(event.getTransport());
break;
diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ProtonHandler.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ProtonHandler.java
index 17f17b0c70..e794b5e08c 100644
--- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ProtonHandler.java
+++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ProtonHandler.java
@@ -373,13 +373,22 @@ public class ProtonHandler extends ProtonInitializable implements SaslListener {
public void flush() {
if (workerExecutor.inEventLoop()) {
+ handleFlush();
+ } else {
+ runLater(this::handleFlush);
+ }
+ }
+
+ private void handleFlush() {
+ try {
transport.process();
+ } catch (Exception ex) {
+ logger.debug("AMQP Transport threw error while processing input: {}", ex.getMessage());
+ if (transport.getCondition() == null) {
+ transport.setCondition(new ErrorCondition(AmqpError.INTERNAL_ERROR, ex.getMessage()));
+ }
+ } finally {
dispatch();
- } else {
- runLater(() -> {
- transport.process();
- dispatch();
- });
}
}
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AMQPProtocolErrorHandlingTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AMQPProtocolErrorHandlingTest.java
new file mode 100644
index 0000000000..86368364e9
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AMQPProtocolErrorHandlingTest.java
@@ -0,0 +1,180 @@
+/*
+ * 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.amqp;
+
+import java.lang.invoke.MethodHandles;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.activemq.artemis.api.core.QueueConfiguration;
+import org.apache.activemq.artemis.api.core.RoutingType;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.utils.Wait;
+import org.apache.qpid.proton.amqp.transport.AmqpError;
+import org.apache.qpid.protonj2.test.driver.ProtonTestClient;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests that validate that an AMQP protocol level error is handled and connections are closed.
+ */
+public class AMQPProtocolErrorHandlingTest extends AmqpClientTestSupport {
+
+ private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ @Test
+ @Timeout(30)
+ public void testBrokerHandlesOutOfOrderDeliveryIdInTransfer() throws Exception {
+ server.start();
+ server.createQueue(QueueConfiguration.of("test").setRoutingType(RoutingType.ANYCAST)
+ .setAddress("test")
+ .setAutoCreated(false));
+
+ try (ProtonTestClient receivingPeer = new ProtonTestClient()) {
+ receivingPeer.queueClientSaslAnonymousConnect();
+ receivingPeer.connect("localhost", AMQP_PORT);
+ receivingPeer.waitForScriptToComplete(5, TimeUnit.SECONDS);
+
+ // Broker response
+ receivingPeer.expectOpen();
+ receivingPeer.expectBegin();
+ receivingPeer.expectAttach().ofSender();
+ receivingPeer.expectAttach().ofReceiver();
+ receivingPeer.expectFlow();
+
+ // Attach a sender and receiver
+ receivingPeer.remoteOpen().withContainerId("test-sender").now();
+ receivingPeer.remoteBegin().withNextOutgoingId(100).now();
+ receivingPeer.remoteAttach().ofReceiver()
+ .withName("transfer-test")
+ .withSource().withAddress("test")
+ .withCapabilities("queue").also()
+ .withTarget().and()
+ .now();
+ receivingPeer.remoteFlow().withLinkCredit(10).now();
+ receivingPeer.remoteAttach().ofSender()
+ .withInitialDeliveryCount(0)
+ .withName("transfer-test")
+ .withTarget().withAddress("test")
+ .withCapabilities("queue").also()
+ .withSource().and()
+ .now();
+
+ receivingPeer.waitForScriptToComplete(5, TimeUnit.SECONDS);
+
+ Wait.assertTrue(() -> server.queueQuery(SimpleString.of("test")).isExists(), 5000, 100);
+ Wait.assertEquals(1, () -> server.locateQueue(SimpleString.of("test")).getConsumerCount(), 5000, 100);
+
+ // Broker response
+ receivingPeer.expectTransfer();
+ receivingPeer.expectDisposition().withSettled(true).withState().accepted();
+
+ // Initial message with correct delivery ID
+ receivingPeer.remoteTransfer().withDeliveryId(100)
+ .withBody().withValue("test").also()
+ .withMessageAnnotations().withAnnotation("x-opt-jms-dest", 0).also()
+ .now();
+
+ receivingPeer.waitForScriptToComplete(5, TimeUnit.SECONDS);
+ receivingPeer.expectClose().withError(AmqpError.INTERNAL_ERROR.toString()).respond();
+
+ logger.info("Sent transfer with delivery ID:100, now sending incorrect delivery ID:99");
+
+ Wait.assertEquals(1, () -> server.locateQueue(SimpleString.of("test")).getDeliveringCount(), 5000, 100);
+
+ // Next message with incorrect delivery ID (should be 101 but send as 99)
+ receivingPeer.remoteTransfer().withDeliveryId(99)
+ .withBody().withValue("test").also()
+ .withMessageAnnotations().withAnnotation("x-opt-jms-dest", 0).also()
+ .now();
+
+ Wait.assertEquals(0, () -> server.locateQueue(SimpleString.of("test")).getConsumerCount(), 5000, 100);
+ Wait.assertEquals(0, () -> server.locateQueue(SimpleString.of("test")).getDeliveringCount(), 5000, 100);
+
+ receivingPeer.waitForScriptToComplete();
+ }
+ }
+
+ @Test
+ @Timeout(30)
+ public void testBrokerHandlesNewTransferSentBeforeLastTransferCompleted() throws Exception {
+ server.start();
+ server.createQueue(QueueConfiguration.of("test").setRoutingType(RoutingType.ANYCAST)
+ .setAddress("test")
+ .setAutoCreated(false));
+
+ try (ProtonTestClient receivingPeer = new ProtonTestClient()) {
+ receivingPeer.queueClientSaslAnonymousConnect();
+ receivingPeer.connect("localhost", AMQP_PORT);
+ receivingPeer.waitForScriptToComplete(5, TimeUnit.SECONDS);
+
+ // Broker response
+ receivingPeer.expectOpen();
+ receivingPeer.expectBegin();
+ receivingPeer.expectAttach().ofSender();
+ receivingPeer.expectAttach().ofReceiver();
+ receivingPeer.expectFlow();
+
+ // Attach a sender and receiver
+ receivingPeer.remoteOpen().withContainerId("test-sender").now();
+ receivingPeer.remoteBegin().withNextOutgoingId(100).now();
+ receivingPeer.remoteAttach().ofReceiver()
+ .withName("transfer-test")
+ .withSource().withAddress("test")
+ .withCapabilities("queue").also()
+ .withTarget().and()
+ .now();
+ receivingPeer.remoteFlow().withLinkCredit(10).now();
+ receivingPeer.remoteAttach().ofSender()
+ .withInitialDeliveryCount(0)
+ .withName("transfer-test")
+ .withTarget().withAddress("test")
+ .withCapabilities("queue").also()
+ .withSource().and()
+ .now();
+
+ receivingPeer.waitForScriptToComplete(5, TimeUnit.SECONDS);
+
+ Wait.assertTrue(() -> server.queueQuery(SimpleString.of("test")).isExists(), 5000, 100);
+ Wait.assertEquals(1, () -> server.locateQueue(SimpleString.of("test")).getConsumerCount(), 5000, 100);
+
+ // Initial message with correct delivery ID indicating more bytes to come
+ receivingPeer.remoteTransfer().withDeliveryId(100)
+ .withBody().withValue("test").also()
+ .withMessageAnnotations().withAnnotation("x-opt-jms-dest", 0).also()
+ .withMore(true)
+ .now();
+
+ receivingPeer.waitForScriptToComplete(5, TimeUnit.SECONDS);
+ receivingPeer.expectClose().withError(AmqpError.INTERNAL_ERROR.toString()).respond();
+
+ logger.info("Sent transfer with delivery ID:100, now sending incorrect delivery ID:101");
+
+ // Last delivery indicated more transfer frames incoming, but we start a new transfer ID:101
+ receivingPeer.remoteTransfer().withDeliveryId(101)
+ .withBody().withValue("test").also()
+ .withMessageAnnotations().withAnnotation("x-opt-jms-dest", 0).also()
+ .now();
+
+ Wait.assertEquals(0, () -> server.locateQueue(SimpleString.of("test")).getConsumerCount(), 5000, 100);
+ Wait.assertEquals(0, () -> server.locateQueue(SimpleString.of("test")).getDeliveringCount(), 5000, 100);
+
+ receivingPeer.waitForScriptToComplete();
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@activemq.apache.org
For additional commands, e-mail: commits-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact