Exit before starting the vip check routine if possible

This commit is contained in:
Kyle Havlovitz 2021-12-10 13:58:43 -08:00
parent 04ef1c3fa0
commit ecbd3eb2a6
2 changed files with 9 additions and 3 deletions

View File

@ -125,10 +125,14 @@ func (s *Server) pruneCARoots() error {
func (s *Server) runVirtualIPVersionCheck(ctx context.Context) error {
// Return early if the flag is already set.
_, err := s.setVirtualIPVersionFlag()
done, err := s.setVirtualIPVersionFlag()
if err != nil {
s.loggers.Named(logging.Connect).Warn("error enabling virtual IPs", "error", err)
}
if done {
s.leaderRoutineManager.Stop(virtualIPCheckRoutineName)
return nil
}
ticker := time.NewTicker(virtualIPVersionCheckInterval)
defer ticker.Stop()
@ -138,12 +142,12 @@ func (s *Server) runVirtualIPVersionCheck(ctx context.Context) error {
case <-ctx.Done():
return nil
case <-ticker.C:
ok, err := s.setVirtualIPVersionFlag()
done, err := s.setVirtualIPVersionFlag()
if err != nil {
s.loggers.Named(logging.Connect).Warn("error enabling virtual IPs", "error", err)
continue
}
if ok {
if done {
return nil
}
}

View File

@ -2126,7 +2126,9 @@ func TestLeader_EnableVirtualIPs(t *testing.T) {
t.Skip("too slow for testing.Short")
}
orig := virtualIPVersionCheckInterval
virtualIPVersionCheckInterval = 50 * time.Millisecond
t.Cleanup(func() { virtualIPVersionCheckInterval = orig })
conf := func(c *Config) {
c.Bootstrap = false