This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 7f48fbdf46 Follow-up to "Make SimpleTcpCluster.stopInternal() cleanup 
robust..."
7f48fbdf46 is described below

commit 7f48fbdf46173b3c873bf115b348dd91a3758c5f
Author: Mark Thomas <[email protected]>
AuthorDate: Fri Oct 2 16:46:17 2026 +0100

    Follow-up to "Make SimpleTcpCluster.stopInternal() cleanup robust..."
    
    - broaden the catch statements to catch Throwable
    - collect the exceptions and re-thrown at end (aligned with Lifecyle)
---
 .../apache/catalina/ha/tcp/SimpleTcpCluster.java   | 67 ++++++++++++++++++----
 1 file changed, 56 insertions(+), 11 deletions(-)

diff --git a/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java 
b/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java
index 1a297ef34a..e34e4f823f 100644
--- a/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java
+++ b/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java
@@ -54,6 +54,7 @@ import org.apache.catalina.util.LifecycleMBeanBase;
 import org.apache.catalina.util.ToStringUtil;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
+import org.apache.tomcat.util.ExceptionUtils;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -690,22 +691,32 @@ public class SimpleTcpCluster extends LifecycleMBeanBase
     protected void stopInternal() throws LifecycleException {
 
         setState(LifecycleState.STOPPING);
+        LifecycleException stopException = null;
 
         if (clusterDeployer != null) {
-            clusterDeployer.stop();
+            try {
+                clusterDeployer.stop();
+            } catch (Throwable t) {
+                log.error(sm.getString("simpleTcpCluster.stopUnable"), t);
+                stopException = handleExceptionDuringStop(stopException, t);
+            }
         }
         this.managers.clear();
         try {
             if (clusterDeployer != null) {
                 clusterDeployer.setCluster(null);
             }
-        } catch (Exception e) {
-            log.error(sm.getString("simpleTcpCluster.stopUnable"), e);
+        } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
+            log.error(sm.getString("simpleTcpCluster.stopUnable"), t);
+            stopException = handleExceptionDuringStop(stopException, t);
         }
         try {
             channel.stop(channelStartOptions);
-        } catch (Exception e) {
-            log.error(sm.getString("simpleTcpCluster.stopUnable"), e);
+        } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
+            log.error(sm.getString("simpleTcpCluster.stopUnable"), t);
+            stopException = handleExceptionDuringStop(stopException, t);
         }
         // These steps must also run when stopping the channel failed,
         // otherwise the cluster valves remain in the container pipeline and
@@ -713,22 +724,56 @@ public class SimpleTcpCluster extends LifecycleMBeanBase
         try {
             channel.removeChannelListener(this);
             channel.removeMembershipListener(this);
-        } catch (Exception e) {
-            log.error(sm.getString("simpleTcpCluster.stopUnable"), e);
+        } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
+            log.error(sm.getString("simpleTcpCluster.stopUnable"), t);
+            stopException = handleExceptionDuringStop(stopException, t);
         }
         try {
             unregisterClusterValve();
-        } catch (Exception e) {
-            log.error(sm.getString("simpleTcpCluster.stopUnable"), e);
+        } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
+            log.error(sm.getString("simpleTcpCluster.stopUnable"), t);
+            stopException = handleExceptionDuringStop(stopException, t);
         }
         // Unregister the MBeans of the local member and of any remote members
         // for which memberDisappeared() did not fire during the stop
         for (ObjectName oname : memberOnameMap.values()) {
-            unregister(oname);
+            try {
+                unregister(oname);
+            } catch (Throwable t) {
+                ExceptionUtils.handleThrowable(t);
+                log.error(sm.getString("simpleTcpCluster.stopUnable"), t);
+                stopException = handleExceptionDuringStop(stopException, t);
+            }
         }
         memberOnameMap.clear();
 
-        channel.setUtilityExecutor(null);
+        try {
+            channel.setUtilityExecutor(null);
+        } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
+            log.error(sm.getString("simpleTcpCluster.stopUnable"), t);
+            stopException = handleExceptionDuringStop(stopException, t);
+        }
+
+        if (stopException != null) {
+            throw stopException;
+        }
+    }
+
+
+    private LifecycleException handleExceptionDuringStop(LifecycleException 
stopException, Throwable t) {
+        if (stopException == null) {
+            if (t instanceof LifecycleException le) {
+                return le;
+            } else {
+                return new 
LifecycleException(sm.getString("simpleTcpCluster.stopUnable"), t);
+            }
+        } else {
+            stopException.addSuppressed(t);
+            return stopException;
+        }
     }
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to