Sent from my iPad On Feb 22, 2012, at 6:51 PM, Nick Urbanik <nick.urba...@optusnet.com.au> wrote:
> Dear Larry, > > On 22/02/12 18:16 -0800, Larry Lile wrote: >> On Wed, Feb 22, 2012 at 6:14 PM, Larry Lile <larry.l...@dreamworks.com> >> 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. This code is used for persistent connections, as you have seen there is no good way to detect that the server has closed your connection. The most effective method is to trap the socket I/O error, reconnect and re execute the failed command. Persistent or not, expect to lose your connection at any time and recover. You could reach through and turn on keep alives on the underlying socket. That isn't the best solution either since it doesn't address what happens if the server itself goes away. The error check will also recover that as well. My LDAP server run about 10k ops/sec. They also disconnect any client that has been idle for 300 seconds. > >> 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 nick.urba...@optusnet.com.au > GPG: 7FFA CDC7 5A77 0558 DC7A 790A 16DF EC5B BB9D 2C24 ID: BB9D2C24 > I disclaim, therefore I am.