You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2010/06/22 11:21:27 UTC
svn commit: r956832 - in /tomcat/trunk:
java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
webapps/docs/changelog.xml webapps/docs/config/listeners.xml
Author: markt
Date: Tue Jun 22 09:21:25 2010
New Revision: 956832
URL: http://svn.apache.org/viewvc?rev=956832&view=rev
Log:
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.
Modified:
tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
tomcat/trunk/webapps/docs/changelog.xml
tomcat/trunk/webapps/docs/config/listeners.xml
Modified: tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java?rev=956832&r1=956831&r2=956832&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java Tue Jun 22 09:21:25 2010
@@ -80,6 +80,19 @@ public class JreMemoryLeakPreventionList
this.gcDaemonProtection = gcDaemonProtection;
}
+ /**
+ * Protect against the memory leak caused when the first call to
+ * <code>sun.net.www.http.HttpClient</code> 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 <code>true</code>.
+ */
+ 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 JreMemoryLeakPreventionList
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
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=956832&r1=956831&r2=956832&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Tue Jun 22 09:21:25 2010
@@ -55,6 +55,12 @@
<add>
Add entryPoint support to the CSRF prevention filter. (markt)
</add>
+ <fix>
+ <bug>49230</bug>: Enhance JRE leak prevention listener with protection
+ for the keep-alive thread started by
+ <code>sun.net.www.http.HttpClient</code>. Patch provided by Rob Kooper.
+ (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">
Modified: tomcat/trunk/webapps/docs/config/listeners.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/listeners.xml?rev=956832&r1=956831&r2=956832&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/listeners.xml (original)
+++ tomcat/trunk/webapps/docs/config/listeners.xml Tue Jun 22 09:21:25 2010
@@ -260,6 +260,16 @@ service:jmx:rmi://<hostname>:10002
startup on non-Sun JVMs. The default is <code>true</code>.</p>
</attribute>
+ <attribute name="keepAliveProtection" required="false">
+ <p>Enables protection so that the KeepAlive thread started by
+ <code>sun.net.www.http.HttpClient</code> does not result in a memory
+ leak. The thread is started the first time the <code>HttpClient</code>
+ 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 <code>true</code>.</p>
+ </attribute>
+
<attribute name="tokenPollerProtection" required="false">
<p>Enables protection so that any token poller thread initialized by
<code>sun.security.pkcs11.SunPKCS11.initToken()</code> does not
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org