From: markt Date: Tue, 22 Jun 2010 09:21:25 +0000 (+0000) Subject: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49230 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=bc0d3ee7c03cb669470ad575e4e7a43f00ca5223;p=tomcat7.0 Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49230 Enhance JRE leak prevention listener with protection for the keep-alive thread started by sun.net.www.http.HttpClient Patch provided by Rob Kooper. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@956832 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java b/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java index 800a9eb4f..b243d83fa 100644 --- a/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java +++ b/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java @@ -80,6 +80,19 @@ public class JreMemoryLeakPreventionListener implements LifecycleListener { this.gcDaemonProtection = gcDaemonProtection; } + /** + * Protect against the memory leak caused when the first call to + * sun.net.www.http.HttpClient is triggered by a web + * application. This first call will start a KeepAlive thread with the + * thread's context class loader configured to be the web application class + * loader. Defaults to true. + */ + private boolean keepAliveProtection = true; + public boolean isKeepAliveProtection() { return keepAliveProtection; } + public void setKeepAliveProtection(boolean keepAliveProtection) { + this.keepAliveProtection = keepAliveProtection; + } + /** * Protect against the memory leak, when the initialization of the * Java Cryptography Architecture is triggered by initializing @@ -177,6 +190,21 @@ public class JreMemoryLeakPreventionListener implements LifecycleListener { log.error(sm.getString("jreLeakListener.gcDaemonFail"), e); } } + + /* + * When a servlet opens a connection using a URL it will use + * sun.net.www.http.HttpClient which keeps a static reference to a + * keep-alive cache which is loaded using the web application class + * loader. + */ + if (keepAliveProtection) { + try { + Class.forName("sun.net.www.http.HttpClient"); + } catch (ClassNotFoundException e) { + log.error("Could not prevent sun.net.www.http.HttpClient" + + " from being loaded.", e); + } + } /* * Creating a MessageDigest during web application startup diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 0a1288002..8cc260050 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -55,6 +55,12 @@ Add entryPoint support to the CSRF prevention filter. (markt) + + 49230: Enhance JRE leak prevention listener with protection + for the keep-alive thread started by + sun.net.www.http.HttpClient. Patch provided by Rob Kooper. + (markt) + diff --git a/webapps/docs/config/listeners.xml b/webapps/docs/config/listeners.xml index 9f3d023a1..c15c03f98 100644 --- a/webapps/docs/config/listeners.xml +++ b/webapps/docs/config/listeners.xml @@ -260,6 +260,16 @@ service:jmx:rmi://<hostname>:10002/jndi/rmi://<hostname>:10001/jmxrm startup on non-Sun JVMs. The default is true.

+ +

Enables protection so that the KeepAlive thread started by + sun.net.www.http.HttpClient does not result in a memory + leak. The thread is started the first time the HttpClient + class is used. Without this protection, if a web application uses this + class the KeepAlive thread will be configured with the thread's context + class loader set to the web application class loader which in turn will + trigger a memory leak on reload. Defaults to true.

+
+

Enables protection so that any token poller thread initialized by sun.security.pkcs11.SunPKCS11.initToken() does not