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 50d00c7b18 Review "Synchronize access to the async timeout scheduling 
state"
50d00c7b18 is described below

commit 50d00c7b18ae99d1e2dd5ddcda5cb259a2370a6d
Author: Mark Thomas <[email protected]>
AuthorDate: Fri Oct 30 20:00:23 2026 +0000

    Review "Synchronize access to the async timeout scheduling state"
    
    Ensure timeout thread stops when protocol does
---
 java/org/apache/coyote/AbstractProtocol.java | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/java/org/apache/coyote/AbstractProtocol.java 
b/java/org/apache/coyote/AbstractProtocol.java
index a7272ebd00..98ba3cff50 100644
--- a/java/org/apache/coyote/AbstractProtocol.java
+++ b/java/org/apache/coyote/AbstractProtocol.java
@@ -91,11 +91,12 @@ public abstract class AbstractProtocol<S> implements 
ProtocolHandler, MBeanRegis
     /** Set of processors currently waiting for async processing. */
     private final Set<Processor> waitingProcessors = 
ConcurrentHashMap.newKeySet();
 
-    /** Controller for the timeout scheduling. Accessed under 
timeoutSchedulingLock. */
-    private ScheduledFuture<?> timeoutFuture = null;
     /** Scheduled future for the periodic monitor task. */
     private volatile ScheduledFuture<?> monitorFuture;
 
+    /** Controller for the timeout scheduling. Accessed under 
timeoutSchedulingLock. */
+    private ScheduledFuture<?> timeoutFuture = null;
+    private boolean timeoutEnabled;
     /** Guards the scheduling of the asynchronous timeout task. */
     private final Object timeoutSchedulingLock = new Object();
 
@@ -1009,6 +1010,9 @@ public abstract class AbstractProtocol<S> implements 
ProtocolHandler, MBeanRegis
         }
 
         endpoint.start();
+        synchronized (timeoutSchedulingLock) {
+            timeoutEnabled = true;
+        }
         monitorFuture = 
getUtilityExecutor().scheduleWithFixedDelay(this::startAsyncTimeout, 0, 60, 
TimeUnit.SECONDS);
     }
 
@@ -1028,12 +1032,14 @@ public abstract class AbstractProtocol<S> implements 
ProtocolHandler, MBeanRegis
                         
getLog().error(sm.getString("abstractProtocolHandler.asyncTimeoutError"), e);
                     }
                 }
-                timeoutFuture = getUtilityExecutor().scheduleAtFixedRate(() -> 
{
-                    long now = System.currentTimeMillis();
-                    for (Processor processor : waitingProcessors) {
-                        processor.timeoutAsync(now);
-                    }
-                }, 1, 1, TimeUnit.SECONDS);
+                if (timeoutEnabled) {
+                    timeoutFuture = 
getUtilityExecutor().scheduleAtFixedRate(() -> {
+                        long now = System.currentTimeMillis();
+                        for (Processor processor : waitingProcessors) {
+                            processor.timeoutAsync(now);
+                        }
+                    }, 1, 1, TimeUnit.SECONDS);
+                }
             }
         }
     }
@@ -1047,6 +1053,7 @@ public abstract class AbstractProtocol<S> implements 
ProtocolHandler, MBeanRegis
                 timeoutFuture.cancel(false);
                 timeoutFuture = null;
             }
+            timeoutEnabled = false;
         }
     }
 


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

Reply via email to