LDAP race condition with ldap_initialize API in OpenLDAP 2.6.7

venugopal chinnakotla <[email protected]> Fri, 5 Sep 2025 14:47:52 +0530
Newsgroups gmane.network.openldap.technical,gmane.network.openldap.devel
Message-ID <CAJCMw6sEiGJMQKyLuocayB9Ndr+AVvNzO=MAB_hSiiMPXr6-mA@mail.gmail.com>
--000000000000a50bdc063e0a50dc
Content-Type: text/plain; charset="UTF-8"

Hi Team,

We are working on migration of nsldap C sdk to OpenLDAP C sdk for our
application client code.

We are using OpenLDAP 2.6.7.

As part of this migration activity,we used ldap_initialize() API for
initializing and getting LDAP Handle. Our application supports multi
threading. So, ldap_initialize() API will be called from multi threaded
code. For example, 2 threads will call ldap_initialize() at same
time/simultaneously.

When 2 threads call ldap_initialize() at same time, sometimes observed a
race condition during this API call. Due to this, the next api calls
ldap_simple_bind_s or ldap_start_tls_s are getting failed for 2 threads and
it is not recovered automatically until restarts our applications. We
observed this race condition multiple times.

Because of this issue, we are unable to start our application and it
becomes a blocker for us to proceed further.

After checking ldap_initialze() API code from openldap source code, noticed
that race condition happened while initializing/setting global options.

Are there any known issues with OpenLDAP when we use it in multi thread
supported applications?

Could you please check and provide a solution.

Thank you for your help.

--000000000000a50bdc063e0a50dc
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><br clear=3D"all"></div><div>Hi Team,<br><br>We are w=
orking on migration of nsldap C sdk to OpenLDAP C sdk for our application c=
lient code.<br><br>We are using OpenLDAP 2.6.7.<br><br>As part of this migr=
ation activity,we used ldap_initialize() API for initializing and getting L=
DAP Handle. Our application supports multi threading. So, ldap_initialize()=
 API will be called from multi threaded code. For example, 2 threads will c=
all ldap_initialize() at same time/simultaneously. <br><br>When 2 threads c=
all ldap_initialize() at same time, sometimes observed a race condition dur=
ing this API call. Due to this, the next api calls ldap_simple_bind_s or ld=
ap_start_tls_s are getting failed for 2 threads and it is not recovered aut=
omatically until restarts our applications. We observed this race condition=
 multiple times.<br><br>Because of this issue, we are unable to start our a=
pplication and it becomes a blocker for us to proceed further.<br><br>After=
 checking ldap_initialze() API code from openldap source code, noticed that=
 race condition happened while initializing/setting global options.<br><br>=
Are there any known issues with OpenLDAP when we use it in multi thread sup=
ported applications?<br><br>Could you please check and provide a solution.<=
br><br>Thank you for your help.</div></div>

--000000000000a50bdc063e0a50dc--