From 729a604192edd2943e1464de998626c76b808ebd Mon Sep 17 00:00:00 2001
From: Nadezhda Ivanova <nivanova@symas.com>
Date: Tue, 2 Apr 2024 13:34:07 +0300
Subject: [PATCH 1/1] ITS#10193 Asyncmeta starts more than one timeout loop per
 database and slaptest crashes

Reference:https://git.openldap.org/openldap/openldap/-/commit/729a604192edd2943e1464de998626c76b808ebd
Conflict:NA

---
 servers/slapd/back-asyncmeta/config.c | 9 ++++++---
 servers/slapd/back-asyncmeta/init.c   | 2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/servers/slapd/back-asyncmeta/config.c b/servers/slapd/back-asyncmeta/config.c
index fbc9681418..aae054ab0a 100644
--- a/servers/slapd/back-asyncmeta/config.c
+++ b/servers/slapd/back-asyncmeta/config.c
@@ -497,7 +497,8 @@ asyncmeta_cfadd( Operation *op, SlapReply *rs, Entry *p, ConfigArgs *c )
 static int
 asyncmeta_back_new_target(
 	a_metatarget_t	**mtp,
-	a_metainfo_t     *mi )
+	a_metainfo_t     *mi,
+	BackendDB        *db )
 {
 	a_metatarget_t		*mt;
 
@@ -516,7 +517,9 @@ asyncmeta_back_new_target(
 	mt->mt_idassert_flags = LDAP_BACK_AUTH_PRESCRIPTIVE;
 
 	*mtp = mt;
-
+	if ( !SLAP_DBOPEN(db) || !(slapMode & SLAP_SERVER_MODE)) {
+		return 0;
+	}
 	for ( i = 0; i < mi->mi_num_conns; i++ ) {
 		a_metaconn_t *mc = &mi->mi_conns[i];
 		mc->mc_conns = ch_realloc( mc->mc_conns, sizeof( a_metasingleconn_t ) * mi->mi_ntargets);
@@ -1907,7 +1910,7 @@ asyncmeta_back_cf_gen( ConfigArgs *c )
 			return 1;
 		}
 
-		if ( asyncmeta_back_new_target( &mi->mi_targets[ i ], mi ) != 0 ) {
+		if ( asyncmeta_back_new_target( &mi->mi_targets[ i ], mi, c->be ) != 0 ) {
 			snprintf( c->cr_msg, sizeof( c->cr_msg ),
 				"unable to init server"
 				" in \"%s <protocol>://<server>[:port]/<naming context>\"",
diff --git a/servers/slapd/back-asyncmeta/init.c b/servers/slapd/back-asyncmeta/init.c
index 5c8016fb2b..45fccf03ec 100644
--- a/servers/slapd/back-asyncmeta/init.c
+++ b/servers/slapd/back-asyncmeta/init.c
@@ -275,7 +275,7 @@ asyncmeta_back_db_open(
 	
 	ber_dupbv ( &mi->mi_suffix, &be->be_suffix[0] );
 
-	if ( mi->mi_ntargets > 0 ) {
+	if ( ( slapMode & SLAP_SERVER_MODE ) && mi->mi_ntargets > 0 ) {
 		ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
 		mi->mi_task = ldap_pvt_runqueue_insert( &slapd_rq, 1,
 							asyncmeta_timeout_loop, mi, "asyncmeta_timeout_loop", mi->mi_suffix.bv_val );
-- 
2.33.0

