[Date Prev][Date Next] [Chronological] [Thread] [Top]

RE: ldap_simple_bind blocks while connecting; is not asynchronous (ITS#2720)



> -----Original Message-----
> From: owner-openldap-bugs@OpenLDAP.org
> [mailto:owner-openldap-bugs@OpenLDAP.org]On Behalf Of henrik@hswn.dk

> According to the manpage, "The ldap_simple_bind() call is
> asynchronous, taking
> the same parameters but only initiating the bind operation
> and  returning the
> message id of the request it sent."
>
> Combined with the timeout parameter in ldap_result(), I
> understood this to mean
> that you can attempt to establish a connection to an ldap server with
> ldap_simple_bind(), and have control of how long to wait for
> it the connection
> establishment and bind operation to complete.

Binding is not the same as connecting. However, if the Bind happens to be the
first operation on the LDAP handle, it will trigger the connect attempt, and
will be blocked until the connect finishes. Whatever the operation is, the
first op on the LDAP handle triggers the connect attempt, and doesn't execute
until the connect completes.

> However, it seems that ldap_simple_bind() is not asynchronous
> while establishing
> the TCP connection. If there is no response from the host
> that I try to connect
> to, then the ldap_simple_bind() call hangs until the TCP
> connect times out. This
> can easily take several minutes.

> Is this intentional ? And if yes, is there a way to control
> the connect timeout
> other than using alarm() to interrupt the operation ?

Use
	struct timeval tv;
	ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &tv);

where tv is initialized to the timeout you want on the connect() attempt.

  -- Howard Chu
  Chief Architect, Symas Corp.       Director, Highland Sun
  http://www.symas.com               http://highlandsun.com/hyc
  Symas: Premier OpenSource Development and Support