Author: kkolinko
Date: Sun Jan  9 00:57:34 2011
New Revision: 1056851

URL: http://svn.apache.org/viewvc?rev=1056851&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50556
Improve JreMemoryLeakPreventionListener against leak caused by LdapPoolManager

I am treating the additional patch as CTR (not waiting for the third vote), 
because it does not affect code besides an unused import.

Modified:
    tomcat/tc6.0.x/trunk/STATUS.txt
    
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties
    tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
    tomcat/tc6.0.x/trunk/webapps/docs/config/listeners.xml

Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=1056851&r1=1056850&r2=1056851&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Sun Jan  9 00:57:34 2011
@@ -149,13 +149,3 @@ PATCHES PROPOSED TO BACKPORT:
   http://svn.apache.org/viewvc?rev=1056569&view=rev
   +1: kkolinko
   -1:
-
-* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50556
-  Improve JreMemoryLeakPreventionListener against leak caused by 
LdapPoolManager
-  Patch tc 6: 
http://people.apache.org/~slaurent/patches/2011-01-07_BZ50556_jre_leak_ldapPoolManager.patch
-  +1: slaurent, rjung, kkolinko
-  -1:
-  Additional patch:
-  http://svn.apache.org/viewvc?rev=1056576&view=rev
-  +1: kkolinko, rjung
-  -1:

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java?rev=1056851&r1=1056850&r2=1056851&view=diff
==============================================================================
--- 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
 (original)
+++ 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/JreMemoryLeakPreventionListener.java
 Sun Jan  9 00:57:34 2011
@@ -162,6 +162,20 @@ public class JreMemoryLeakPreventionList
         this.xmlParsingProtection = xmlParsingProtection;
     }
     
+    /**
+     * <code>com.sun.jndi.ldap.LdapPoolManager</code> class spawns a thread 
when it
+     * is initialized if the system property
+     * <code>com.sun.jndi.ldap.connect.pool.timeout</code> is greater than 0.
+     * That thread inherits the context class loader of the current thread, so
+     * that there may be a web application class loader leak if the web app
+     * is the first to use <code>LdapPoolManager</code>. 
+     */
+    private boolean ldapPoolProtection = true;
+    public boolean isLdapPoolProtection() { return ldapPoolProtection; }
+    public void setLdapPoolProtection(boolean ldapPoolProtection) {
+        this.ldapPoolProtection = ldapPoolProtection;
+    }
+    
     public void lifecycleEvent(LifecycleEvent event) {
         // Initialise these classes when Tomcat starts
         if (Lifecycle.INIT_EVENT.equals(event.getType())) {
@@ -357,6 +371,22 @@ public class JreMemoryLeakPreventionList
                                 e);
                     }
                 }
+                
+                if (ldapPoolProtection) {
+                    try {
+                        Class.forName("com.sun.jndi.ldap.LdapPoolManager");
+                    } catch (ClassNotFoundException e) {
+                        if (System.getProperty("java.vendor").startsWith(
+                                "Sun")) {
+                            log.error(sm.getString(
+                                    "jreLeakListener.ldapPoolManagerFail"), e);
+                        } else {
+                            log.debug(sm.getString(
+                                    "jreLeakListener.ldapPoolManagerFail"), e);
+                        }
+                    }
+                }
+
             } finally {
                 Thread.currentThread().setContextClassLoader(loader);
             }

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=1056851&r1=1056850&r2=1056851&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties 
Sun Jan  9 00:57:34 2011
@@ -65,6 +65,7 @@ jreLeakListener.gcDaemonFail=Failed to t
 jreLeakListener.jarUrlConnCacheFail=Failed to disable Jar URL connection 
caching by default
 jreLeakListener.xmlParseFail=Error whilst attempting to prevent memory leaks 
during XML parsing
 jreLeakListener.authPolicyFail=Error whilst attempting to prevent memory leak 
in javax.security.auth.Policy class
+jreLeakListener.ldapPoolManagerFail=Failed to trigger creation of the 
com.sun.jndi.ldap.LdapPoolManager class during Tomcat start to prevent possible 
memory leaks. This is expected on non-Sun JVMs.
 naming.wsdlFailed=Failed to find wsdl file: {0}
 naming.bindFailed=Failed to bind object: {0}
 naming.jmxRegistrationFailed=Failed to register in JMX: {0}

Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=1056851&r1=1056850&r2=1056851&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Sun Jan  9 00:57:34 2011
@@ -213,6 +213,13 @@
         <bug>50459</bug>: Fix thread/classloader binding issues in
         StandardContext. (slaurent) 
       </fix>
+      <add>
+        <bug>50556</bug>: Improve JreMemoryLeakPreventionListener to prevent
+        a potential class loader leak caused by a thread spawned when the class
+        <code>com.sun.jndi.ldap.LdapPoolManager</code> is initialized and the 
+        system property <code>com.sun.jndi.ldap.connect.pool.timeout</code> is 
+        set to a value greater than 0. (slaurent)
+      </add>
     </changelog>
   </subsection>
   <subsection name="Coyote">

Modified: tomcat/tc6.0.x/trunk/webapps/docs/config/listeners.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/config/listeners.xml?rev=1056851&r1=1056850&r2=1056851&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/config/listeners.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/config/listeners.xml Sun Jan  9 00:57:34 
2011
@@ -270,6 +270,19 @@ service:jmx:rmi://&lt;hostname&gt;:10002
         trigger a memory leak on reload. Defaults to <code>true</code>.</p>
       </attribute>
 
+      <attribute name="ldapPoolProtection" required="false">
+        <p>Enables protection so that the PoolCleaner thread started by
+        <code>com.sun.jndi.ldap.LdapPoolManager</code> does not result in a 
+        memory leak. The thread is started the first time the 
+        <code>LdapPoolManager</code> class is used if the system property 
+        <code>com.sun.jndi.ldap.connect.pool.timeout</code> is set to a value
+        greater than 0. Without this protection, if a web application uses 
this 
+        class the PoolCleaner 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="securityLoginConfigurationProtection" required="false">
         <p>Enables protection so that usage of the
         <code>javax.security.auth.login.Configuration</code> class by a web 



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to