This is an automated email from the ASF dual-hosted git repository. markt 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 8c4afe4 Fix BZ 59203 - Try Thread.interrupt() before Thread.stop() 8c4afe4 is described below commit 8c4afe44381eac40a6c7a6e62b094ef42ef72762 Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Apr 23 12:29:18 2020 +0100 Fix BZ 59203 - Try Thread.interrupt() before Thread.stop() https://bz.apache.org/bugzilla/show_bug.cgi?id=59203 --- .../catalina/loader/WebappClassLoaderBase.java | 36 +++++++++++----------- webapps/docs/changelog.xml | 7 +++++ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/java/org/apache/catalina/loader/WebappClassLoaderBase.java b/java/org/apache/catalina/loader/WebappClassLoaderBase.java index 23ccad0..d22263b 100644 --- a/java/org/apache/catalina/loader/WebappClassLoaderBase.java +++ b/java/org/apache/catalina/loader/WebappClassLoaderBase.java @@ -1713,7 +1713,7 @@ public abstract class WebappClassLoaderBase extends URLClassLoader @SuppressWarnings("deprecation") // thread.stop() private void clearReferencesThreads() { Thread[] threads = getThreads(); - List<Thread> executorThreadsToStop = new ArrayList<>(); + List<Thread> threadsToStop = new ArrayList<>(); // Iterate over the set of threads for (Thread thread : threads) { @@ -1809,29 +1809,29 @@ public abstract class WebappClassLoaderBase extends URLClassLoader thread.getName(), getContextName()), e); } - if (usingExecutor) { - // Executor may take a short time to stop all the - // threads. Make a note of threads that should be - // stopped and check them at the end of the method. - executorThreadsToStop.add(thread); - } else { - // This method is deprecated and for good reason. This - // is very risky code but is the only option at this - // point. A *very* good reason for apps to do this - // clean-up themselves. - thread.stop(); + // Stopping an executor automatically interrupts the + // associated threads. For non-executor threads, interrupt + // them here. + if (!usingExecutor && !thread.isInterrupted()) { + thread.interrupt(); } + + // Threads are expected to take a short time to stop after + // being interrupted. Make a note of all threads that are + // expected to stop to enable them to be checked at the end + // of this method. + threadsToStop.add(thread); } } } - // If thread stopping is enabled, executor threads should have been - // stopped above when the executor was shut down but that depends on the - // thread correctly handling the interrupt. Give all the executor - // threads a few seconds shutdown and if they are still running - // Give threads up to 2 seconds to shutdown + // If thread stopping is enabled, threads should have been stopped above + // when the executor was shut down or the thread was interrupted but + // that depends on the thread correctly handling the interrupt. Check + // each thread and if any are still running give all threads up to a + // total of 2 seconds to shutdown. int count = 0; - for (Thread t : executorThreadsToStop) { + for (Thread t : threadsToStop) { while (t.isAlive() && count < 100) { try { Thread.sleep(20); diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index a7de3b8..b657b4b 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -71,6 +71,13 @@ Add more descriptive error message in DefaultServlet for SC_NOT_FOUND. (michaelo) </add> + <add> + <bug>59203</bug>: Before calling <code>Thread.stop()</code> (if + configured to do so) on a web application created thread that is not + stopped by the web application when the web application is stopped, try + interrupting the thread first. Based on a pull request by Govinda + Sakhare. (markt) + </add> <fix> <bug>64309</bug>; Improve the regular expression used to search for class loader repositories when bootstrapping Tomcat. Pull request --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org