[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Freeipa-devel] [PATCH 0211] Improve error handling in code for LDAP modification



Hello,

Improve error handling in code for LDAP modification.

Failed LDAP modification is retried once.

This patch should go to branches v3 and master.

--
Petr^2 Spacek


From f92881a2e0fa32e7f84816b10984f1e6745d0176 Mon Sep 17 00:00:00 2001
From: Petr Spacek <pspacek redhat com>
Date: Wed, 11 Dec 2013 12:10:50 +0100
Subject: [PATCH] Improve error handling in code for LDAP modification.

Failed LDAP modification is retried once.

Signed-off-by: Petr Spacek <pspacek redhat com>
---
 src/ldap_helper.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/ldap_helper.c b/src/ldap_helper.c
index c5ecd00bc17154cf083840d04eb4fa82c895ff45..ca98023bc796b4f6c2f87abe62115597d43c3083 100644
--- a/src/ldap_helper.c
+++ b/src/ldap_helper.c
@@ -2399,7 +2399,7 @@ handle_connection_error(ldap_instance_t *ldap_inst, ldap_connection_t *ldap_conn
 		/* Try to reconnect on other errors. */
 		log_ldap_error(ldap_conn->handle, "connection error");
 reconnect:
-		if (ldap_conn->tries == 0)
+		if (ldap_conn->handle == NULL)
 			log_error("connection to the LDAP server was lost");
 		result = ldap_connect(ldap_inst, ldap_conn, force);
 		if (result == ISC_R_SUCCESS)
@@ -2417,6 +2417,7 @@ ldap_modify_do(ldap_instance_t *ldap_inst, const char *dn, LDAPMod **mods,
 	int ret;
 	int err_code;
 	const char *operation_str;
+	isc_boolean_t once = ISC_FALSE;
 	isc_result_t result;
 	ldap_connection_t *ldap_conn = NULL;
 
@@ -2444,7 +2445,9 @@ ldap_modify_do(ldap_instance_t *ldap_inst, const char *dn, LDAPMod **mods,
 		 * successful
 		 * TODO: handle this case inside ldap_pool_getconnection()?
 		 */
-		CHECK(ldap_connect(ldap_inst, ldap_conn, ISC_FALSE));
+retry:
+		once = ISC_TRUE;
+		CHECK(handle_connection_error(ldap_inst, ldap_conn, ISC_FALSE));
 	}
 
 	if (delete_node) {
@@ -2503,7 +2506,13 @@ ldap_modify_do(ldap_instance_t *ldap_inst, const char *dn, LDAPMod **mods,
 	if ((mods[0]->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_DELETE ||
 	    err_code != LDAP_NO_SUCH_ATTRIBUTE) {
 		result = ISC_R_FAILURE;
+		if (once == ISC_FALSE) {
+			log_error("retrying LDAP operation (%s) on entry '%s'",
+				  operation_str, dn);
+			goto retry;
+		}
 	}
+
 cleanup:
 	ldap_pool_putconnection(ldap_inst->pool, &ldap_conn);
 
-- 
1.8.3.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]