From 430b51643de3749532d831d297ba31a46feb52d4 Mon Sep 17 00:00:00 2001 From: "mahlon@laika.com" Date: Tue, 8 Jan 2013 19:27:59 +0000 Subject: [PATCH] Attempt to retry the operation on failure. Less-than-optimal behavior reported by Alexander Perlis . FossilOrigin-Name: ccbc3dc1b0e9f73b6b73f2c9ab1bd2d30f798c9d8e7efbdb8b0f178045239b96 --- shelldap | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/shelldap b/shelldap index 7d69a78..c0d2521 100755 --- a/shelldap +++ b/shelldap @@ -681,20 +681,30 @@ sub search attrs => $opts->{'attrs'} || ['*'] ); + # since search is used just about everywhere, this seems like + # a pretty good place to check for connection errors and try + # to re-establish a connection. + # + if ( $s->code() != 0 ) { + $self->debug( "Error ". $s->code() . ", retrying.\n" ); + $self->{'ldap'} = undef; + + $s = $self->ldap->search( + base => $opts->{'base'}, + filter => $opts->{'filter'}, + scope => $opts->{'scope'}, + timelimit => $conf->{'timeout'}, + typesonly => ! $opts->{'vals'}, + attrs => $opts->{'attrs'} || ['*'] + ); + } + my $rv = { code => $s->code(), message => $s->error(), entries => [] }; - # since search is used just about everywhere, this seems like - # a pretty good place to check for connection errors. - # - # check for a lost connection, kill cached object so we - # try to reconnect on the next search. - # - $self->{'ldap'} = undef if $s->code() == LDAP_SERVER_DOWN; - $rv->{'entries'} = $opts->{'scope'} eq 'base' ? [ $s->shift_entry() ] : [ $s->entries() ];