# HG changeset patch # User Mahlon E. Smith # Date 1357673279 28800 # Node ID b8836c9018fbd5579c681895ef42b81501de4a23 # Parent b8c6d4e8f828c0f7049d3887a7204e2bd4f4a792 Attempt to retry the operation on failure. Less-than-optimal behavior reported by Alexander Perlis . diff -r b8c6d4e8f828 -r b8836c9018fb shelldap --- a/shelldap Tue Nov 27 11:32:41 2012 -0800 +++ b/shelldap Tue Jan 08 11:27:59 2013 -0800 @@ -681,20 +681,30 @@ 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() ];