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/13 12:21:49 UTC

[tomcat] branch master updated: Always retry on a new connection, even when pooling

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


The following commit(s) were added to refs/heads/master by this push:
     new 35b2d79  Always retry on a new connection, even when pooling
35b2d79 is described below

commit 35b2d79ad26535deedcc0c6bea2a057138e1bd30
Author: remm <re...@apache.org>
AuthorDate: Tue Oct 13 14:19:54 2020 +0200

    Always retry on a new connection, even when pooling
    
    This keeps the same very simple design as for the single connection
    scenario, for now.
---
 java/org/apache/catalina/realm/JNDIRealm.java | 22 +++++++++++++++++++---
 webapps/docs/changelog.xml                    |  5 +++++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/catalina/realm/JNDIRealm.java b/java/org/apache/catalina/realm/JNDIRealm.java
index 9ab4c10..a6012bd 100644
--- a/java/org/apache/catalina/realm/JNDIRealm.java
+++ b/java/org/apache/catalina/realm/JNDIRealm.java
@@ -1303,7 +1303,7 @@ public class JNDIRealm extends RealmBase {
                 close(connection);
 
                 // open a new directory context.
-                connection = get();
+                connection = get(true);
 
                 // Try the authentication again.
                 principal = authenticate(connection, username, credentials);
@@ -2373,12 +2373,28 @@ 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) {
-            connection = connectionPool.pop();
-            if (connection == null) {
+            if (create) {
                 connection = create();
+            } else {
+                connection = connectionPool.pop();
+                if (connection == null) {
+                    connection = create();
+                }
             }
         } else {
             singleConnectionLock.lock();
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index d935750..97cf512 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -58,6 +58,11 @@
         <bug>64805</bug>: Correct imports used by <code>JMXPorxyServlet</code>.
         (markt)
       </fix>
+      <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)
+      </fix>
     </changelog>
   </subsection>
   <subseciton name="Coyote">


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