Rework do_ldap retry loop to better handle server down errors.

Could likely treat other errors (LDAP_BUSY) as non-fatal errors.
This commit is contained in:
Kurt Zeilenga 2001-09-27 03:13:28 +00:00
parent 9ab1282f5d
commit af37269416

View file

@ -53,7 +53,7 @@ static int do_unbind LDAP_P(( Ri * ));
/* /*
* Determine the type of ldap operation being performed and call the * Determine the type of ldap operation being performed and call the
* appropriate routine. * appropriate routine.
* - If successful, returns ERR_DO_LDAP_OK * - If successful, returns DO_LDAP_OK
* - If a retryable error occurs, ERR_DO_LDAP_RETRYABLE is returned. * - If a retryable error occurs, ERR_DO_LDAP_RETRYABLE is returned.
* The caller should wait a while and retry the operation. * The caller should wait a while and retry the operation.
* - If a fatal error occurs, ERR_DO_LDAP_FATAL is returned. The caller * - If a fatal error occurs, ERR_DO_LDAP_FATAL is returned. The caller
@ -62,91 +62,95 @@ static int do_unbind LDAP_P(( Ri * ));
*/ */
int int
do_ldap( do_ldap(
Ri *ri, Ri *ri,
Re *re, Re *re,
char **errmsg char **errmsg
) )
{ {
int rc = 0; int retry = 2;
int lderr = LDAP_SUCCESS; *errmsg = NULL;
int retry = 2;
*errmsg = NULL; do {
int lderr;
if ( ri->ri_ldp == NULL ) {
lderr = do_bind( ri, &lderr );
while ( retry > 0 ) { if ( lderr != BIND_OK ) {
if ( ri->ri_ldp == NULL ) { return DO_LDAP_ERR_RETRYABLE;
rc = do_bind( ri, &lderr ); }
}
if ( rc != BIND_OK ) { switch ( re->re_changetype ) {
return DO_LDAP_ERR_RETRYABLE; case T_ADDCT:
} lderr = op_ldap_add( ri, re, errmsg );
} if ( lderr != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY,
"Error: ldap_add_s failed adding \"%s\": %s\n",
*errmsg ? *errmsg : ldap_err2string( lderr ),
re->re_dn, 0 );
}
break;
switch ( re->re_changetype ) { case T_MODIFYCT:
case T_ADDCT: lderr = op_ldap_modify( ri, re, errmsg );
lderr = op_ldap_add( ri, re, errmsg ); if ( lderr != LDAP_SUCCESS ) {
if ( lderr != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_ANY,
Debug( LDAP_DEBUG_ANY, "Error: ldap_modify_s failed modifying \"%s\": %s\n",
"Error: ldap_add_s failed adding \"%s\": %s\n", *errmsg ? *errmsg : ldap_err2string( lderr ),
*errmsg ? *errmsg : ldap_err2string( lderr ), re->re_dn, 0 );
re->re_dn, 0 ); }
} break;
break;
case T_MODIFYCT:
lderr = op_ldap_modify( ri, re, errmsg );
if ( lderr != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY,
"Error: ldap_modify_s failed modifying \"%s\": %s\n",
*errmsg ? *errmsg : ldap_err2string( lderr ),
re->re_dn, 0 );
}
break;
case T_DELETECT:
lderr = op_ldap_delete( ri, re, errmsg );
if ( lderr != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY,
"Error: ldap_delete_s failed deleting \"%s\": %s\n",
*errmsg ? *errmsg : ldap_err2string( lderr ),
re->re_dn, 0 );
}
break;
case T_MODRDNCT:
lderr = op_ldap_modrdn( ri, re, errmsg );
if ( lderr != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY,
"Error: ldap_modrdn_s failed modifying %s: %s\n",
*errmsg ? *errmsg : ldap_err2string( lderr ),
re->re_dn, 0 );
}
break;
default:
Debug( LDAP_DEBUG_ANY,
"Error: do_ldap: bad op \"%d\", dn = \"%s\"\n",
re->re_changetype, re->re_dn, 0 );
return DO_LDAP_ERR_FATAL;
}
/* case T_DELETECT:
* Analyze return code. If ok, just return. If LDAP_SERVER_DOWN, lderr = op_ldap_delete( ri, re, errmsg );
* we may have been idle long enough that the remote slapd timed if ( lderr != LDAP_SUCCESS ) {
* us out. Rebind and try again. Debug( LDAP_DEBUG_ANY,
*/ "Error: ldap_delete_s failed deleting \"%s\": %s\n",
if ( lderr == LDAP_SUCCESS ) { *errmsg ? *errmsg : ldap_err2string( lderr ),
return DO_LDAP_OK; re->re_dn, 0 );
} else if ( lderr == LDAP_SERVER_DOWN ) { }
/* The LDAP server may have timed us out - rebind and try again */ break;
(void) do_unbind( ri );
retry--; case T_MODRDNCT:
} else { lderr = op_ldap_modrdn( ri, re, errmsg );
return DO_LDAP_ERR_FATAL; if ( lderr != LDAP_SUCCESS ) {
} Debug( LDAP_DEBUG_ANY,
} "Error: ldap_modrdn_s failed modifying %s: %s\n",
return DO_LDAP_ERR_FATAL; *errmsg ? *errmsg : ldap_err2string( lderr ),
re->re_dn, 0 );
}
break;
default:
Debug( LDAP_DEBUG_ANY,
"Error: do_ldap: bad op \"%d\", dn = \"%s\"\n",
re->re_changetype, re->re_dn, 0 );
return DO_LDAP_ERR_FATAL;
}
/*
* Analyze return code. If ok, just return. If LDAP_SERVER_DOWN,
* we may have been idle long enough that the remote slapd timed
* us out. Rebind and try again.
*/
switch( lderr ) {
case LDAP_SUCCESS:
return DO_LDAP_OK;
default:
return DO_LDAP_ERR_FATAL;
case LDAP_SERVER_DOWN: /* server went down */
(void) do_unbind( ri );
retry--;
}
} while ( retry > 0 );
return DO_LDAP_ERR_RETRYABLE;
} }
/* /*
* Perform an ldap add operation. * Perform an ldap add operation.
*/ */