From: Arran Cudbard-Bell Date: Thu, 14 Oct 2021 18:02:50 +0000 (-0500) Subject: ldap: Retry ldap_result if it's the first loop through the demuxer X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=746aab6827793c0ff004e995756f8ee53475753c;p=thirdparty%2Ffreeradius-server.git ldap: Retry ldap_result if it's the first loop through the demuxer ...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. --- diff --git a/src/lib/ldap/connection.c b/src/lib/ldap/connection.c index ae1721673ca..803ae231a2a 100644 --- a/src/lib/ldap/connection.c +++ b/src/lib/ldap/connection.c @@ -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; }