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

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


The following commit(s) were added to refs/heads/main by this push:
     new 0a16194c06 Review "Synchronize access to the async timeout scheduling 
state"
0a16194c06 is described below

commit 0a16194c06e1dbe011456037ef84e27711ac3ec4
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 6236a78379..cd2371a7a4 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();
 
@@ -978,6 +979,9 @@ public abstract class AbstractProtocol<S> implements 
ProtocolHandler, MBeanRegis
         }
 
         endpoint.start();
+        synchronized (timeoutSchedulingLock) {
+            timeoutEnabled = true;
+        }
         monitorFuture = 
getUtilityExecutor().scheduleWithFixedDelay(this::startAsyncTimeout, 0, 60, 
TimeUnit.SECONDS);
     }
 
@@ -997,12 +1001,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);
+                }
             }
         }
     }
@@ -1016,6 +1022,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