Use LDAP_OPT_KEEPCONN to prevent the target connection from being freed

On error, the ldap connection was freed and under some circumstances the fd was being reused,
which caused an assertion error in connection_init.
This commit is contained in:
Nadezhda Ivanova 2019-02-28 16:46:58 +02:00 committed by Quanah Gibson-Mount
parent f239bbd3c6
commit ea1eb19303
2 changed files with 10 additions and 3 deletions

View file

@ -182,6 +182,9 @@ asyncmeta_init_one_conn(
op->o_log_prefix, rs->sr_err );
goto error_return;
}
ldap_set_option( msc->msc_ld, LDAP_OPT_KEEPCONN, LDAP_OPT_ON);
msc->msc_ldr = ldap_dup(msc->msc_ld);
if (!msc->msc_ldr) {
ldap_ld_free(msc->msc_ld, 0, NULL, NULL);
@ -1037,7 +1040,7 @@ int asyncmeta_start_one_listener(a_metaconn_t *mc,
msc = &mc->mc_conns[candidate];
if ( slapd_shutdown || !META_BACK_CONN_INITED( msc ) || msc->msc_ld == NULL
|| !META_IS_CANDIDATE( &candidates[ candidate ] )) {
|| META_BACK_CONN_INVALID(msc) || !META_IS_CANDIDATE( &candidates[ candidate ] )) {
return LDAP_SUCCESS;
}
bc->msgids[candidate] = candidates[candidate].sr_msgid;

View file

@ -1510,6 +1510,7 @@ again:
if (rc < 1) {
if (rc < 0) {
ldap_get_option( mc->mc_conns[i].msc_ldr, LDAP_OPT_ERROR_NUMBER, &rc);
META_BACK_CONN_INVALID_SET(&mc->mc_conns[i]);
asyncmeta_op_read_error(mc, i, rc, ctx);
}
ldap_pvt_thread_mutex_lock( &mc->mc_om_mutex );
@ -1626,9 +1627,12 @@ retry_bc:
slap_sl_mem_setctx(ctx, oldctx);
if (mc->mc_conns) {
ldap_pvt_thread_mutex_lock( &mc->mc_om_mutex );
for (i=0; i<ntargets; i++)
if (mc->mc_conns[i].msc_ldr && mc->mc_conns[i].conn)
for (i=0; i<ntargets; i++) {
if (!slapd_shutdown && !META_BACK_CONN_INVALID(msc)
&& mc->mc_conns[i].msc_ldr && mc->mc_conns[i].conn) {
connection_client_enable(mc->mc_conns[i].conn);
}
}
ldap_pvt_thread_mutex_unlock( &mc->mc_om_mutex );
}
return NULL;