This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push: new 7fb643d Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63836 7fb643d is described below commit 7fb643d2c0d0c9630fa820d5bdcae5433e30dd9b Author: Mark Thomas <ma...@apache.org> AuthorDate: Mon Oct 28 21:03:33 2019 +0100 Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63836 While the OOME was not observed in 8.5.x, the memory leak at the root of the issue was still present. --- .../org/apache/catalina/startup/ContextConfig.java | 24 ++++++++++++++++++---- webapps/docs/changelog.xml | 4 ++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/java/org/apache/catalina/startup/ContextConfig.java b/java/org/apache/catalina/startup/ContextConfig.java index 75a16db..fa11334 100644 --- a/java/org/apache/catalina/startup/ContextConfig.java +++ b/java/org/apache/catalina/startup/ContextConfig.java @@ -37,8 +37,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Properties; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - import javax.servlet.MultipartConfigElement; import javax.servlet.ServletContainerInitializer; import javax.servlet.ServletContext; @@ -80,6 +78,7 @@ import org.apache.tomcat.util.bcel.classfile.ElementValue; import org.apache.tomcat.util.bcel.classfile.ElementValuePair; import org.apache.tomcat.util.bcel.classfile.JavaClass; import org.apache.tomcat.util.buf.UriUtil; +import org.apache.tomcat.util.collections.ManagedConcurrentWeakHashMap; import org.apache.tomcat.util.descriptor.InputSourceUtil; import org.apache.tomcat.util.descriptor.XmlErrorHandler; import org.apache.tomcat.util.descriptor.web.ContextEjb; @@ -163,8 +162,8 @@ public class ContextConfig implements LifecycleListener { /** * Cache of default web.xml fragments per Host */ - protected static final Map<Host,DefaultWebXmlCacheEntry> hostWebXmlCache = - new ConcurrentHashMap<>(); + protected static final ManagedConcurrentWeakHashMap<Host,DefaultWebXmlCacheEntry> hostWebXmlCache = + new ManagedConcurrentWeakHashMap<>(); /** @@ -306,6 +305,8 @@ public class ContextConfig implements LifecycleListener { if (originalDocBase != null) { context.setDocBase(originalDocBase); } + } else if (event.getType().equals(Lifecycle.PERIODIC_EVENT)) { + hostWebXmlCache.maintain(); } else if (event.getType().equals(Lifecycle.CONFIGURE_STOP_EVENT)) { configureStop(); } else if (event.getType().equals(Lifecycle.AFTER_INIT_EVENT)) { @@ -1599,6 +1600,9 @@ public class ContextConfig implements LifecycleListener { entry = new DefaultWebXmlCacheEntry(webXmlDefaultFragment, globalTimeStamp, hostTimeStamp); hostWebXmlCache.put(host, entry); + // Add a Lifecycle listener to the Host that will remove it from + // the hostWebXmlCache once the Host is destroyed + host.addLifecycleListener(new HostWebXmlCacheCleaner()); } return webXmlDefaultFragment; @@ -2681,6 +2685,18 @@ public class ContextConfig implements LifecycleListener { } } + private static class HostWebXmlCacheCleaner implements LifecycleListener { + + @Override + public void lifecycleEvent(LifecycleEvent event) { + + if (event.getType() == Lifecycle.AFTER_DESTROY_EVENT) { + Host host = (Host) event.getSource(); + hostWebXmlCache.remove(host); + } + } + } + static class JavaClassCacheEntry { public final String superclassName; diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 87e5d44..25c065c 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -59,6 +59,10 @@ Add more details on the usage of <code>RewriteMap</code> functionality in the <code>RewriteValve</code>. (fschumacher) </add> + <fix> + <bug>63836</bug> Ensure that references to the Host object are cleared + once the Host instance is destroyed. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org