Attempt to retry the operation on failure.

Less-than-optimal behavior reported by Alexander Perlis <aperlis@math.lsu.edu>.

FossilOrigin-Name: ccbc3dc1b0e9f73b6b73f2c9ab1bd2d30f798c9d8e7efbdb8b0f178045239b96
This commit is contained in:
mahlon@laika.com 2013-01-08 19:27:59 +00:00
parent f89ceae24e
commit 430b51643d

View file

@ -681,20 +681,30 @@ sub search
attrs => $opts->{'attrs'} || ['*'] 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 = { my $rv = {
code => $s->code(), code => $s->code(),
message => $s->error(), message => $s->error(),
entries => [] 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'} = $rv->{'entries'} =
$opts->{'scope'} eq 'base' ? [ $s->shift_entry() ] : [ $s->entries() ]; $opts->{'scope'} eq 'base' ? [ $s->shift_entry() ] : [ $s->entries() ];