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

View File

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