]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#8102 syncrepl: only use trylock on the cn=config DB
authorHoward Chu <hyc@openldap.org>
Tue, 22 Sep 2020 11:18:52 +0000 (12:18 +0100)
committerQuanah Gibson-Mount <quanah@openldap.org>
Tue, 22 Sep 2020 21:37:09 +0000 (21:37 +0000)
servers/slapd/syncrepl.c

index eedc24abbe976a4fc246b0562d20aa42bbaaf9b5..203180c3a3f8273c9680c368182dbab28f2c047b 100644 (file)
@@ -124,6 +124,7 @@ typedef struct syncinfo_s {
        int                     si_got;
        int                     si_strict_refresh;      /* stop listening during fallback refresh */
        int                     si_too_old;
+       int                     si_is_configdb;
        ber_int_t       si_msgid;
        Avlnode                 *si_presentlist;
        LDAP                    *si_ld;
@@ -974,12 +975,18 @@ get_pmutex(
        syncinfo_t *si
 )
 {
-       while ( ldap_pvt_thread_mutex_trylock( &si->si_cookieState->cs_pmutex )) {
-               if ( slapd_shutdown )
-                       return SYNC_SHUTDOWN;
-               if ( !ldap_pvt_thread_pool_pausecheck( &connection_pool ))
-                       ldap_pvt_thread_yield();
+       if ( !si->si_is_configdb ) {
+               ldap_pvt_thread_mutex_lock( &si->si_cookieState->cs_pmutex );
+       } else {
+               /* avoid deadlock when replicating cn=config */
+               while ( ldap_pvt_thread_mutex_trylock( &si->si_cookieState->cs_pmutex )) {
+                       if ( slapd_shutdown )
+                               return SYNC_SHUTDOWN;
+                       if ( !ldap_pvt_thread_pool_pausecheck( &connection_pool ))
+                               ldap_pvt_thread_yield();
+               }
        }
+
        return 0;
 }
 
@@ -5641,6 +5648,8 @@ add_syncrepl(
        LDAP_LIST_INIT( &si->si_nonpresentlist );
        ldap_pvt_thread_mutex_init( &si->si_mutex );
 
+       si->si_is_configdb = strcmp( c->be->be_suffix[0].bv_val, "cn=config" ) == 0;
+
        rc = parse_syncrepl_line( c, si );
 
        if ( rc == 0 ) {