From 3761461d15b2c40b8ff8552fe56f58db013105f5 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Sat, 8 Aug 2020 01:04:38 +0100 Subject: [PATCH] cleanup router watcher logic --- registry.go | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/registry.go b/registry.go index 70aee7d..eaca934 100644 --- a/registry.go +++ b/registry.go @@ -570,39 +570,27 @@ func (r *rtr) start() error { }() go func() { - var err error - var w registry.Watcher - for { select { case <-r.exit: - if w != nil { - w.Stop() - } return default: - if w == nil { - w, err = r.options.Registry.Watch(registry.WatchDomain(registry.WildcardDomain)) - if err != nil { - if logger.V(logger.WarnLevel, logger.DefaultLogger) { - logger.Warnf("failed creating registry watcher: %v", err) - } - time.Sleep(time.Second) - continue + w, err := r.options.Registry.Watch(registry.WatchDomain(registry.WildcardDomain)) + if err != nil { + if logger.V(logger.WarnLevel, logger.DefaultLogger) { + logger.Warnf("failed creating registry watcher: %v", err) } + time.Sleep(time.Second) + continue } + // watchRegistry calls stop when it's done if err := r.watchRegistry(w); err != nil { if logger.V(logger.WarnLevel, logger.DefaultLogger) { logger.Warnf("Error watching the registry: %v", err) } time.Sleep(time.Second) } - - if w != nil { - w.Stop() - w = nil - } } } }()