Do not overwrite validator list with null.

If Vouch contains a list of validators, and on refresh obtains an empty
list, assume the empty response is a result of an error and do not
remove the existing list in favor of it.

It is possible for network issues to result in an empty response when
requesting an update on the list of validators for which Vouch should
operate.  In this situation, where Vouch already has a list of
validators, it retains that list rather than replace it with the empty
results of the request.

(cherry picked from commit 52c58216cb)
This commit is contained in:
Jim McDonald 2021-03-06 00:24:26 +00:00
parent 88a8c2978b
commit c377442e24
No known key found for this signature in database
GPG Key ID: 89CEB61B2AD2A5E7
1 changed files with 7 additions and 2 deletions

View File

@ -117,10 +117,10 @@ func New(ctx context.Context, params ...Parameter) (*Service, error) {
}
if err := s.refreshAccounts(ctx); err != nil {
return nil, errors.Wrap(err, "failed to fetch accounts")
return nil, errors.Wrap(err, "failed to fetch initial accounts")
}
if err := s.refreshValidators(ctx); err != nil {
return nil, errors.Wrap(err, "failed to fetch validator states")
return nil, errors.Wrap(err, "failed to fetch initial validator states")
}
return s, nil
@ -175,6 +175,11 @@ func (s *Service) refreshAccounts(ctx context.Context) error {
}
log.Trace().Int("accounts", len(accounts)).Msg("Obtained accounts")
if len(accounts) == 0 && len(s.accounts) != 0 {
log.Warn().Msg("No accounts obtained; retaining old list")
return nil
}
s.mutex.Lock()
s.accounts = accounts
s.mutex.Unlock()