Skip to content

Commit 2687162

Browse files
jbertramclaude
andcommitted
ARTEMIS-6217 mitigate shutdown stacktraces for MQTT
When the broker is processing MQTT packets (especially those related to QoS 2 message flows) a shutdown can cause the broker to log several different stack-traces that are effectively harmless, but can alarm users. The broker should detect these and avoid logging them. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 59d4f72 commit 2687162

4 files changed

Lines changed: 50 additions & 1 deletion

File tree

artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTConnectionManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@
1616
*/
1717
package org.apache.activemq.artemis.core.protocol.mqtt;
1818

19+
import java.lang.invoke.MethodHandles;
20+
1921
import io.netty.buffer.ByteBufAllocator;
2022
import io.netty.handler.codec.mqtt.MqttConnectMessage;
2123
import io.netty.handler.codec.mqtt.MqttProperties;
2224
import io.netty.handler.codec.mqtt.MqttVersion;
2325
import org.apache.activemq.artemis.api.core.client.ActiveMQClient;
26+
import org.apache.activemq.artemis.core.persistence.impl.journal.ActiveMQIDGeneratorStoppedException;
2427
import org.apache.activemq.artemis.core.server.ActiveMQServer;
2528
import org.apache.activemq.artemis.core.server.ServerSession;
2629
import org.apache.activemq.artemis.core.server.impl.ServerSessionImpl;
2730
import org.apache.activemq.artemis.utils.UUIDGenerator;
31+
import org.slf4j.Logger;
32+
import org.slf4j.LoggerFactory;
2833

2934
import static io.netty.handler.codec.mqtt.MqttProperties.MqttPropertyType.ASSIGNED_CLIENT_IDENTIFIER;
3035
import static io.netty.handler.codec.mqtt.MqttProperties.MqttPropertyType.AUTHENTICATION_METHOD;
@@ -41,6 +46,8 @@
4146
*/
4247
public class MQTTConnectionManager {
4348

49+
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
50+
4451
private MQTTSession session;
4552

4653
public MQTTConnectionManager(MQTTSession session) {
@@ -194,6 +201,8 @@ synchronized void disconnect(boolean failure) {
194201
try {
195202
session.stop(failure);
196203
session.getConnection().destroy();
204+
} catch (ActiveMQIDGeneratorStoppedException harmless) {
205+
logger.debug("Unable to cleanly disconnect MQTT client {} because the storage manager is stopping", session.getState().getClientId(), harmless);
197206
} catch (Exception e) {
198207
MQTTLogger.LOGGER.errorDisconnectingClient(e);
199208
} finally {

artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTSessionCallback.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@
1616
*/
1717
package org.apache.activemq.artemis.core.protocol.mqtt;
1818

19+
import java.lang.invoke.MethodHandles;
20+
1921
import org.apache.activemq.artemis.api.core.SimpleString;
22+
import org.apache.activemq.artemis.core.persistence.impl.journal.ActiveMQIDGeneratorStoppedException;
2023
import org.apache.activemq.artemis.core.server.MessageReference;
2124
import org.apache.activemq.artemis.core.server.ServerConsumer;
2225
import org.apache.activemq.artemis.spi.core.protocol.SessionCallback;
2326
import org.apache.activemq.artemis.spi.core.remoting.ReadyListener;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
2429

2530
public class MQTTSessionCallback implements SessionCallback {
2631

32+
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
33+
2734
private final MQTTSession session;
2835
private final MQTTConnection connection;
2936
private final int defaultMaximumInFlightPublishMessages;
@@ -50,6 +57,8 @@ public int sendMessage(MessageReference ref,
5057
int deliveryCount) {
5158
try {
5259
session.getMqttPublishManager().publishToClient(ref.getMessage().toCore(), consumer);
60+
} catch (ActiveMQIDGeneratorStoppedException harmless) {
61+
logger.debug("Unable to send message to MQTT client because the storage manager is stopping; consumer: {}; message: {}", consumer, ref, harmless);
5362
} catch (Exception e) {
5463
MQTTLogger.LOGGER.unableToSendMessage(session.getState().getClientId(), ref, e);
5564
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.activemq.artemis.core.persistence.impl.journal;
18+
19+
/**
20+
* Thrown by an {@link org.apache.activemq.artemis.utils.IDGenerator} when an ID is requested after the generator has
21+
* been stopped.
22+
*/
23+
public class ActiveMQIDGeneratorStoppedException extends RuntimeException {
24+
25+
private static final long serialVersionUID = 8328635365036357836L;
26+
27+
public ActiveMQIDGeneratorStoppedException(String message) {
28+
super(message);
29+
}
30+
}

artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.apache.activemq.artemis.api.core.SimpleString;
4949
import org.apache.activemq.artemis.api.core.TransportConfiguration;
5050
import org.apache.activemq.artemis.core.io.SequentialFile;
51+
import org.apache.activemq.artemis.core.persistence.impl.journal.ActiveMQIDGeneratorStoppedException;
5152
import org.apache.activemq.artemis.core.postoffice.Binding;
5253
import org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationSyncFileMessage;
5354
import org.apache.activemq.artemis.core.security.CheckType;
@@ -533,7 +534,7 @@ IllegalStateException invalidRoutingTypeUpdate(String queueName,
533534
IllegalArgumentException positivePowerOfTwo(String name, Number val);
534535

535536
@Message(id = 229257, value = "IDGenerator has been stopped")
536-
RuntimeException idGeneratorStopped();
537+
ActiveMQIDGeneratorStoppedException idGeneratorStopped();
537538

538539
@Message(id = 229258, value = "Invalid cluster bridge message! No queue IDs defined in the property {}")
539540
ActiveMQIllegalStateException noQueueIdsDefined(SimpleString idsHeaderName);

0 commit comments

Comments
 (0)