From 1aaa18b180417135492ae5a16346eed448245ce7 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Wed, 29 Jun 2005 18:16:29 +0000 Subject: [PATCH] more on ITS#3808 --- servers/slapd/back-ldap/bind.c | 49 +++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/servers/slapd/back-ldap/bind.c b/servers/slapd/back-ldap/bind.c index 93aa6abe32..75124c07b7 100644 --- a/servers/slapd/back-ldap/bind.c +++ b/servers/slapd/back-ldap/bind.c @@ -605,16 +605,20 @@ retry:; if ( rs->sr_err == LDAP_SERVER_DOWN ) { if ( retries > 0 ) { - ldap_unbind_ext_s( lc->lc_ld, NULL, NULL ); - lc->lc_ld = NULL; - - /* lc here must be the regular lc, reset and ready for init */ - if ( ldap_back_prepare_conn( &lc, op, rs, sendok ) != LDAP_SUCCESS ) { - return 0; + ldap_pvt_thread_mutex_lock( &li->conn_mutex ); + assert( lc->lc_refcnt > 0 ); + if ( lc->lc_refcnt == 1 ) { + ldap_unbind_ext_s( lc->lc_ld, NULL, NULL ); + lc->lc_ld = NULL; + + /* lc here must be the regular lc, reset and ready for init */ + rs->sr_err = ldap_back_prepare_conn( &lc, op, rs, sendok ); + } + ldap_pvt_thread_mutex_unlock( &li->conn_mutex ); + if ( rs->sr_err == LDAP_SUCCESS ) { + retries--; + goto retry; } - - retries--; - goto retry; } ldap_back_freeconn( op, lc ); @@ -756,19 +760,26 @@ retry:; int ldap_back_retry( struct ldapconn *lc, Operation *op, SlapReply *rs, ldap_back_send_t sendok ) { - int rc; + int rc = 0; + struct ldapinfo *li = (struct ldapinfo *)op->o_bd->be_private; + + ldap_pvt_thread_mutex_lock( &li->conn_mutex ); - ldap_pvt_thread_mutex_lock( &lc->lc_mutex ); - ldap_unbind_ext_s( lc->lc_ld, NULL, NULL ); - lc->lc_ld = NULL; - lc->lc_bound = 0; + if ( lc->lc_refcnt == 1 ) { + ldap_pvt_thread_mutex_lock( &lc->lc_mutex ); + ldap_unbind_ext_s( lc->lc_ld, NULL, NULL ); + lc->lc_ld = NULL; + lc->lc_bound = 0; - /* lc here must be the regular lc, reset and ready for init */ - rc = ldap_back_prepare_conn( &lc, op, rs, sendok ); - if ( rc == LDAP_SUCCESS ) { - rc = ldap_back_dobind_int( lc, op, rs, sendok, 0 ); + /* lc here must be the regular lc, reset and ready for init */ + rc = ldap_back_prepare_conn( &lc, op, rs, sendok ); + if ( rc == LDAP_SUCCESS ) { + rc = ldap_back_dobind_int( lc, op, rs, sendok, 0 ); + } + ldap_pvt_thread_mutex_unlock( &lc->lc_mutex ); } - ldap_pvt_thread_mutex_unlock( &lc->lc_mutex ); + + ldap_pvt_thread_mutex_unlock( &li->conn_mutex ); return rc; } -- 2.39.5