func (s *DefaultSubscriber) configLoop() { // Wait 5 mins for config to load. If we cannot load config by the // then there's most likely a major issue and we should panic. if !config.WaitUntilLoaded(5 * time.Minute) { panic("Waiting 5 mins for config to load") } s.loadFromConfig() ch := config.SubscribeChanges() for { select { case <-ch: s.loadFromConfig() case <-s.stop: break } } }
// loadFromConfig including contiuous retries until we have managed to load it func (v *validatorImpl) loadFromConfig() { if !config.WaitUntilLoaded(waitForConfigDelay) { // put out a warning anyway, to make it clear we are going to struggle to load key log.Warnf("[Auth] Failed to load config after %v, kicking off public key loading anyway...", waitForConfigDelay) } // block until we load attempts := 0 for { if err := v.load(); err != nil { attempts++ delay := time.Duration(int64(startRetryDelay) * int64(attempts)) if delay > maxRetryDelay { delay = maxRetryDelay } log.Tracef("[Auth] Failed to load public key from config: %v (sleeping for %v)", err, delay) time.Sleep(delay) continue } break } }
// setup is a one-time action that loads PUB hosts from config and sets up a config subscriber func (p *HostpoolPublisher) setup() { // Wait 5 mins for config to load. If we cannot load config by the // then there's most likely a major issue and we should panic. if !config.WaitUntilLoaded(5 * time.Minute) { panic("Waiting 5 mins for config to load") } ch := config.SubscribeChanges() p.loadFromConfig() go func() { for { <-ch for { if err := p.loadFromConfig(); err != nil { log.Warnf("Failed to load NSQ PUB config: %v", err) time.Sleep(configRetryDelay) } else { break } } } }() }