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 e600dbdc1e Improve clean-up of failed/removed Valves in Pipeline
e600dbdc1e is described below

commit e600dbdc1e3716d313e9a2b935c1b57420d99595
Author: Mark Thomas <[email protected]>
AuthorDate: Fri May 22 13:05:34 2026 +0100

    Improve clean-up of failed/removed Valves in Pipeline
---
 .../org/apache/catalina/core/StandardPipeline.java | 26 ++++++++++++++--------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/java/org/apache/catalina/core/StandardPipeline.java 
b/java/org/apache/catalina/core/StandardPipeline.java
index 21c24efdb6..23385816a0 100644
--- a/java/org/apache/catalina/core/StandardPipeline.java
+++ b/java/org/apache/catalina/core/StandardPipeline.java
@@ -225,6 +225,7 @@ public class StandardPipeline extends LifecycleBase 
implements Pipeline {
                 ((Lifecycle) valve).start();
             } catch (LifecycleException e) {
                 log.error(sm.getString("standardPipeline.basic.start"), e);
+                cleanupValve(valve);
                 return;
             }
         }
@@ -277,6 +278,8 @@ public class StandardPipeline extends LifecycleBase 
implements Pipeline {
                     ((Lifecycle) valve).start();
                 } catch (LifecycleException e) {
                     log.error(sm.getString("standardPipeline.valve.start"), e);
+                    cleanupValve(valve);
+                    return;
                 }
             }
         }
@@ -363,18 +366,25 @@ public class StandardPipeline extends LifecycleBase 
implements Pipeline {
             first = null;
         }
 
+        cleanupValve(valve);
+
+        container.fireContainerEvent(Container.REMOVE_VALVE_EVENT, valve);
+    }
+
+
+    /*
+     * Performs any necessary clean-up after a Valve failed to be set/added or 
is removed
+     */
+    private void cleanupValve(Valve valve) {
         if (valve instanceof Contained) {
             ((Contained) valve).setContainer(null);
         }
 
         if (valve instanceof Lifecycle) {
-            // Stop this valve if necessary
-            if (getState().isAvailable()) {
-                try {
-                    ((Lifecycle) valve).stop();
-                } catch (LifecycleException e) {
-                    log.error(sm.getString("standardPipeline.valve.stop"), e);
-                }
+            try {
+                ((Lifecycle) valve).stop();
+            } catch (LifecycleException e) {
+                log.error(sm.getString("standardPipeline.valve.stop"), e);
             }
             try {
                 ((Lifecycle) valve).destroy();
@@ -382,8 +392,6 @@ public class StandardPipeline extends LifecycleBase 
implements Pipeline {
                 log.error(sm.getString("standardPipeline.valve.destroy"), e);
             }
         }
-
-        container.fireContainerEvent(Container.REMOVE_VALVE_EVENT, valve);
     }
 
 


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

Reply via email to