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
commit 0f2e084d1583cfa4c00cec1958ec30113fb4f41e Author: Mark Thomas <ma...@apache.org> AuthorDate: Wed Jul 21 17:45:01 2021 +0100 Fix BZ 65454. Correct a timing issue that could delay a request https://bz.apache.org/bugzilla/show_bug.cgi?id=65454 If the work queue is not empty, it is likely that a task was added to the work queue between this thread timing out and the worker count being decremented a few lines above this comment. In this case, create a replacement worker so that the task isn't held in the queue waiting for one of the other workers to finish. --- java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java | 10 ++++++++-- webapps/docs/changelog.xml | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java b/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java index 7b1ec55..8771c22 100644 --- a/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java +++ b/java/org/apache/tomcat/util/threads/ThreadPoolExecutor.java @@ -1050,8 +1050,14 @@ public class ThreadPoolExecutor extends AbstractExecutorService { if (min == 0 && ! workQueue.isEmpty()) { min = 1; } - if (workerCountOf(c) >= min) - { + // https://bz.apache.org/bugzilla/show_bug.cgi?id=65454 + // If the work queue is not empty, it is likely that a task was + // added to the work queue between this thread timing out and + // the worker count being decremented a few lines above this + // comment. In this case, create a replacement worker so that + // the task isn't held in the queue waiting for one of the other + // workers to finish. + if (workerCountOf(c) >= min && workQueue.isEmpty()) { return; // replacement not needed } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 3838cf3..cafd371 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -146,6 +146,12 @@ associated with the response until the connection timed out at which point the final packet would be sent and the connection closed. (markt) </fix> + <fix> + <bug>65454</bug>: Fix a race condition that could result in a delay to + a new request. The new request could be queued to wait for an existing + request to finish processing rather than the thread pool creating a new + thread to process the new request. (markt) + </fix> </changelog> </subsection> <subsection name="Jasper"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org