nkokitkar commented on code in PR #26476:
URL: https://github.com/apache/camel/pull/26476#discussion_r4020297747


##########
components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoConsumer.java:
##########
@@ -74,15 +78,26 @@ protected void doStart() throws Exception {
                 client.connect(connectOptions);
             }
 
-            client.setCallback(new MqttCallbackExtended() {
+            MqttClient callbackClient = client;
+            boolean isOwnedClient = stopClient;
+            callbackClient.setCallback(new MqttCallbackExtended() {
 
                 @Override
                 public void connectComplete(boolean reconnect, String 
serverURI) {
-                    if (reconnect) {
+                    if (reconnect && isRunAllowed() && callbackClient == 
client) {

Review Comment:
   Agreed that the additional lifecycle guards would also improve 
`PahoMqtt5Consumer`. I am keeping that follow-up out of this deprecated MQTT v3 
reliability fix so this PR stays narrowly scoped.
   
   _GitHub Copilot on behalf of nkokitkar_microsoft._



##########
components/camel-paho/src/main/java/org/apache/camel/component/paho/PahoConsumer.java:
##########
@@ -128,6 +143,50 @@ public void deliveryComplete(IMqttDeliveryToken token) {
         }
     }
 
+    private void restartRouteAsync() {
+        if (!restarting.compareAndSet(false, true)) {
+            LOG.debug("Route restart already in progress, skipping duplicate 
restart");
+            return;
+        }
+        String threadName = "Paho-RestartRoute-" + getRouteId();
+        ExecutorService executor = null;
+        try {
+            executor
+                    = 
getEndpoint().getCamelContext().getExecutorServiceManager().newSingleThreadExecutor(this,
 threadName);
+            ExecutorService restartExecutor = executor;

Review Comment:
   I am keeping the defensive executor structure. It lets the same error path 
reset the duplicate-restart guard when executor creation or task submission 
fails, and shut down the executor when one was created, without allowing a 
scheduling exception to escape the MQTT callback.
   
   _GitHub Copilot on behalf of nkokitkar_microsoft._



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to