You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2020/10/19 19:13:56 UTC

[tomcat] branch master updated (cf5130a -> f938e18)

This is an automated email from the ASF dual-hosted git repository.

remm pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git.


    from cf5130a  Remove the entry for org.apache.tomcat.util.descriptor.tld.LocalStrings from tomcat-embed-core's GraalVM tomcat-resource.json. It no more part of the jar since https://github.com/apache/tomcat/commit/3815b4951eb3acd30a0b77aafa75fbdb928d5782 ( Fix unwanted JPMS dependency of embed-core on embed-jasper )
     new f48b718  Drop pooled connections on error
     new f938e18  WS

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 java/org/apache/catalina/realm/JNDIRealm.java | 76 ++++++++++++++++++---------
 webapps/docs/changelog.xml                    |  5 +-
 2 files changed, 55 insertions(+), 26 deletions(-)


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 01/02: Drop pooled connections on error

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit f48b7187951f998a48dc07121fe8593a2015b99d
Author: remm <re...@apache.org>
AuthorDate: Mon Oct 19 20:30:54 2020 +0200

    Drop pooled connections on error
    
    This avoids piling up on stale connections.
    Also getPassword will use the retry logic. It is only called when using
    digest it seems, so it's not used often.
---
 java/org/apache/catalina/realm/JNDIRealm.java | 76 ++++++++++++++++++---------
 webapps/docs/changelog.xml                    |  3 +-
 2 files changed, 54 insertions(+), 25 deletions(-)

diff --git a/java/org/apache/catalina/realm/JNDIRealm.java b/java/org/apache/catalina/realm/JNDIRealm.java
index a6012bd..21e9f17 100644
--- a/java/org/apache/catalina/realm/JNDIRealm.java
+++ b/java/org/apache/catalina/realm/JNDIRealm.java
@@ -1301,9 +1301,10 @@ public class JNDIRealm extends RealmBase {
 
                 // close the connection so we know it will be reopened.
                 close(connection);
+                closePooledConnections();
 
                 // open a new directory context.
-                connection = get(true);
+                connection = get();
 
                 // Try the authentication again.
                 principal = authenticate(connection, username, credentials);
@@ -2190,6 +2191,20 @@ public class JNDIRealm extends RealmBase {
 
     }
 
+    /**
+     * Close all pooled connections.
+     */
+    protected void closePooledConnections() {
+        if (connectionPool != null) {
+            // Close any pooled connections as they might be bad as well
+            synchronized (connectionPool) {
+                JNDIConnection connection = null;
+                while ((connection = connectionPool.pop()) != null) {
+                    close(connection);
+                }
+            }
+        }
+    }
 
     /**
      * Get the password for the specified user.
@@ -2203,8 +2218,36 @@ public class JNDIRealm extends RealmBase {
             return null;
         }
 
+        JNDIConnection connection = null;
+        User user = null;
         try {
-            User user = getUser(get(), username, null);
+
+            // Ensure that we have a directory context available
+            connection = get();
+
+            // Occasionally the directory context will timeout.  Try one more
+            // time before giving up.
+            try {
+                user = getUser(connection, username, null);
+            } catch (NullPointerException | NamingException e) {
+                // log the exception so we know it's there.
+                containerLog.info(sm.getString("jndiRealm.exception.retry"), e);
+
+                // close the connection so we know it will be reopened.
+                close(connection);
+                closePooledConnections();
+
+                // open a new directory context.
+                connection = get();
+
+                // Try the authentication again.
+                user = getUser(connection, username, null);
+            }
+
+
+            // Release this context
+            release(connection);
+
             if (user == null) {
                 // User should be found...
                 return null;
@@ -2212,7 +2255,10 @@ public class JNDIRealm extends RealmBase {
                 // ... and have a password
                 return user.getPassword();
             }
+
         } catch (NamingException e) {
+            // Log the problem for posterity
+            containerLog.error(sm.getString("jndiRealm.exception"), e);
             return null;
         }
 
@@ -2269,6 +2315,7 @@ public class JNDIRealm extends RealmBase {
 
                 // close the connection so we know it will be reopened.
                 close(connection);
+                closePooledConnections();
 
                 // open a new directory context.
                 connection = get();
@@ -2373,28 +2420,12 @@ public class JNDIRealm extends RealmBase {
      * @exception NamingException if a directory server error occurs
      */
     protected JNDIConnection get() throws NamingException {
-        return get(false);
-    }
-
-    /**
-     * Open (if necessary) and return a connection to the configured
-     * directory server for this Realm.
-     * @param create when pooling, this forces creation of a new connection,
-     *   for example after an error
-     * @return the connection
-     * @exception NamingException if a directory server error occurs
-     */
-    protected JNDIConnection get(boolean create) throws NamingException {
         JNDIConnection connection = null;
         // Use the pool if available, otherwise use the single connection
         if (connectionPool != null) {
-            if (create) {
+            connection = connectionPool.pop();
+            if (connection == null) {
                 connection = create();
-            } else {
-                connection = connectionPool.pop();
-                if (connection == null) {
-                    connection = create();
-                }
             }
         } else {
             singleConnectionLock.lock();
@@ -2683,10 +2714,7 @@ public class JNDIRealm extends RealmBase {
             singleConnectionLock.lock();
             close(singleConnection);
         } else {
-            JNDIConnection connection = null;
-            while ((connection = connectionPool.pop()) != null) {
-                close(connection);
-            }
+            closePooledConnections();
             connectionPool = null;
         }
     }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 0e182f2..849f0ba 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -61,7 +61,8 @@
       <fix>
         Fix JNDIRealm pooling problems retrying on another bad connection. Any
         retries are made on a new connection, just like with the single
-        connection scenario. (remm)
+        connection scenario. Also remove all connections from the pool after
+        an error. (remm)
       </fix>
       <fix>
         Remove the entry for <code>org.apache.tomcat.util.descriptor.tld.LocalStrings</code>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[tomcat] 02/02: WS

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit f938e1864387038994cc34ce1ba45e4fa2813a77
Author: remm <re...@apache.org>
AuthorDate: Mon Oct 19 20:31:53 2020 +0200

    WS
---
 webapps/docs/changelog.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 849f0ba..f174bc9 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -116,7 +116,7 @@
         <bug>64799</bug>: Added missing resources to host-manager web app. (isapir)
       </fix>
       <fix>
-        <bug>64797</bug>: Align manager.xml template file in Host-Manager with 
+        <bug>64797</bug>: Align manager.xml template file in Host-Manager with
         context.xml of real Manager web application. (isapir)
       </fix>
     </changelog>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org