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

markt 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 73591d0dd1 Fix spurious wait. Code is unused in normal Tomcat usage.
73591d0dd1 is described below

commit 73591d0dd12e0405c30422b0391e6725f20774ff
Author: Mark Thomas <[email protected]>
AuthorDate: Sat Aug 30 14:58:16 2025 +0100

    Fix spurious wait. Code is unused in normal Tomcat usage.
    
    Identified by Coverity scan
---
 .../apache/tomcat/util/threads/InlineExecutorService.java  | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/java/org/apache/tomcat/util/threads/InlineExecutorService.java 
b/java/org/apache/tomcat/util/threads/InlineExecutorService.java
index 5be02c469e..dfbdf11353 100644
--- a/java/org/apache/tomcat/util/threads/InlineExecutorService.java
+++ b/java/org/apache/tomcat/util/threads/InlineExecutorService.java
@@ -55,11 +55,17 @@ public class InlineExecutorService extends 
AbstractExecutorService {
 
     @Override
     public boolean awaitTermination(long timeout, TimeUnit unit) throws 
InterruptedException {
+       long timeoutExpiry = System.nanoTime() + unit.toNanos(timeout);
+       long timeoutMillis = unit.toMillis(timeout);
         synchronized (lock) {
-            if (terminated) {
-                return true;
-            }
-            lock.wait(unit.toMillis(timeout));
+               /*
+                * Spurious wake-ups are possible. Keep waiting until the 
service has been terminated or the timeout has
+                * expired. 
+                */
+               while (!terminated && timeoutMillis > 0) {
+                       lock.wait(timeoutMillis);
+                       timeoutMillis = (timeoutExpiry - System.nanoTime()) / 
1_000_000;
+               }
             return terminated;
         }
     }


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

Reply via email to