Re: How determine if persistent Net::LDAP object is alive?

Nick Urbanik <[email protected]> Thu, 23 Feb 2012 13:51:32 +1100
Newsgroups gmane.comp.lang.perl.modules.ldap
Message-ID <[email protected]>
Dear Larry,

On 22/02/12 18:16 -0800, Larry Lile wrote:
>On Wed, Feb 22, 2012 at 6:14 PM, Larry Lile <[email protected]> wrote:
>    I've always just trapped for the disconnect at the operation,
>    this is also a convenient place to check for referrals.
>
>            # XXX Check for I/O Error on update, reconnect and
>            # XXX retry if possible.  This could be much more sophisticated.
>            $ldap = ldap_open($ldap) and $result = $entry->update($ldap)
>                if $result->code == LDAP_OPERATIONS_ERROR and
>                $result->error =~ m!I/O Error!i;
>
>    ldap_open is the same function I use to open an LDAP server
>    normally.  When passed an existing LDAP object it will attempt
>    to shut it down as cleanly as possible.

But it seems that you are aiming for *non*-persistent connections; it
seems to me that you are closing the connection if it exists.

The problem there is that if there is a very high load, and there are
many connections and disconnections, it is possible to consume too
many TCP connections.  (Our LDAP servers can be *very* busy).

What we are aiming for is to maintain a *persistent* LDAP connection,
but to determine when it has failed before depending on it.

>    I haven't tested this code
>    in a while, $result->error =~ m!I/O Error!i may not be correct
>    since the latest updates to Net::LDAP.
>
>
>    sub ldap_open
>    {
>        my $ldap = shift;
>
>    ...
>
>        if ($ldap)
>        {
>            warn "\nConnection to ", $ldap->{net_ldap_host},
>                " broken, attempting to reconnect.\n"
>                if $opt_v;
>
>            # XXX Try to close the socket as best we can.
>            close $ldap->{net_ldap_socket};
>
>            foreach my $server (split(/\s+/, $ldap_opt{'host'}))
>            {
>                ($server, my $port) = split(/:/, $server, 2);
>                $port = $ldap_opt{'port'} if ! $port;
>                last if lc $server eq lc $ldap->{net_ldap_host};
>                push @servers, shift @servers;
>            }
>        }
>
>    The remainder of the code builds a connection to the LDAP server as usual
>    returning it's object to the c
>
>
>Pardon the interruption there.  =)
>
>The remainder of the code builds a connection to the LDAP server as usual
>returning it's object to the caller.
-- 
Nick Urbanik http://nicku.org 808-71011 [email protected]
GPG: 7FFA CDC7 5A77 0558 DC7A 790A 16DF EC5B BB9D 2C24  ID: BB9D2C24
I disclaim, therefore I am.