]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
ldap: Retry ldap_result if it's the first loop through the demuxer
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 14 Oct 2021 18:02:50 +0000 (13:02 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 14 Oct 2021 21:49:46 +0000 (16:49 -0500)
...the demuxer was called for a reason.  It's unlikely we'd get a read notification on the socket and there _really_ be no result.

src/lib/ldap/connection.c

index ae1721673cab2b6165f93dd6193406dcfd7f456f..803ae231a2af65ceca5913757deb0550e8a5665b 100644 (file)
@@ -751,6 +751,7 @@ static void ldap_trunk_request_demux(fr_trunk_connection_t *tconn, fr_connection
        fr_ldap_rcode_t         rcode;
        fr_ldap_query_t         find = { .msgid = -1 }, *query = NULL;
        request_t               *request;
+       bool                    really_no_result = false;
 
        /*
         *  Reset the idle timeout event
@@ -762,12 +763,20 @@ static void ldap_trunk_request_demux(fr_trunk_connection_t *tconn, fr_connection
                /*
                 *      Look for any results for which we have the complete result message
                 *      ldap_result will return a pointer to a chain of messages.
+                *
+                *      The first time ldap_result is called when there's pending network
+                *      data, it may read the data, but not return any results.
+                *
+                *      In order to fix the spurious debugging messages and overhead,
+                *      if this is the first iteration through the loop and ldap_result
+                *      returns no result (0), we call it again.
                 */
                ret = ldap_result(ldap_conn->handle, LDAP_RES_ANY, LDAP_MSG_ALL, &poll, &result);
-
                switch (ret) {
                case 0:
-                       return;
+                       if (really_no_result) return;
+                       really_no_result = true;
+                       continue;
 
                case -1:
                        rcode = fr_ldap_error_check(NULL, ldap_conn, NULL, NULL);
@@ -778,6 +787,10 @@ static void ldap_trunk_request_demux(fr_trunk_connection_t *tconn, fr_connection
                        return;
 
                default:
+                       /*
+                        *      We only retry ldap_result the first time through the loop.
+                        */
+                       really_no_result = true;
                        break;
                }