[PATCH] do_reconnect: expiry check of dclist BEFORE lookup using it

Patrick Cernko <[email protected]> Thu, 2 Oct 2025 12:52:49 +0200
Newsgroups org.kernel.vger.autofs
Organization Information Services & Technology, Joint Administration, Max Planck Institute for Informatics & Max Planck Institute for Software Systems
Message-ID <[email protected]>
Hi autofs developers,

this patch changes the behavior when to refresh LDAP SRV records. The documentation 
states:

> The server list returned from an SRV RR lookup is refreshed according to the minimum ttl found in the SRV RR records or after one hour, whichever is less.

But the code in fact does not do any refreshing as long as at least one server in the 
dclist still responds.

This issue became obvious in our setup, when we had to disable the first two servers: 
autofs continued to contact ldap-a and ldap-b, running in timeouts (~5sec) and 
finally got an answer from ldap-c. But due to the timeouts every mount took >10sec 
resulting in slow responsiveness for the whole system. Changing the SRV records (with 
TTLs of 7200) did not help. As a workaround we had to signal all client's automount 
processes with HUP.

The change invalidates the dclist if expired. This forces autofs to do a new SRV 
record lookup before doing the LDAP lookup.

Best regards,
-- 
Patrick Cernko <[email protected]> +49 681 9325 5815
Joint Scientific IT and Technical Service
Max-Planck-Institute für Informatik & Softwaresysteme



Signed-off-by: Patrick Cernko <[email protected]>
---
  modules/lookup_ldap.c | 18 ++++++++++--------
  1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
index 53416c6..45a3754 100644
--- a/modules/lookup_ldap.c
+++ b/modules/lookup_ldap.c
@@ -1155,17 +1155,11 @@ static int do_reconnect(unsigned logopt,
  		return ret;
  	}

-	if (ctxt->dclist) {
-		dcrv = find_dc_server(logopt, conn, ctxt->dclist->uri, ctxt);
-		if (dcrv == NSS_STATUS_SUCCESS) {
-			ldapinit_mutex_unlock();
-			return dcrv;
-		}
-	}
-
  	uris_mutex_lock(ctxt);
  	if (ctxt->dclist) {
  		if (!conn->ldap || ctxt->dclist->expire < monotonic_time(NULL)) {
+                        debug(logopt, MODPREFIX
+                              "dclist expired, removing it to force new lookup");
  			free_dclist(ctxt->dclist);
  			ctxt->dclist = NULL;
  		}
@@ -1176,6 +1170,14 @@ static int do_reconnect(unsigned logopt,
  	}
  	uris_mutex_unlock(ctxt);

+	if (ctxt->dclist) {
+		dcrv = find_dc_server(logopt, conn, ctxt->dclist->uri, ctxt);
+		if (dcrv == NSS_STATUS_SUCCESS) {
+			ldapinit_mutex_unlock();
+			return dcrv;
+		}
+	}
+
  	if (!ctxt->uri)
  		goto find_server;

-- 
2.39.5
smime.p7s (application/pkcs7-signature, 4.8 KB) - not displayed