diff --git a/src/aggregator/aggregator/election_mgr.go b/src/aggregator/aggregator/election_mgr.go index 7f3d0b55e8..38aa4d0f01 100644 --- a/src/aggregator/aggregator/election_mgr.go +++ b/src/aggregator/aggregator/election_mgr.go @@ -572,6 +572,20 @@ func (mgr *electionManager) campaignState() campaignState { return mgr.campaignStateWatchable.Get().(campaignState) } +func (mgr *electionManager) checkCampaignState() { + enabled, err := mgr.campaignIsEnabledFn() + if err != nil { + mgr.metrics.campaignCheckErrors.Inc(1) + return + } + newState := newCampaignState(enabled) + currState := mgr.campaignState() + if currState == newState { + return + } + mgr.processCampaignStateChange(newState) +} + func (mgr *electionManager) checkCampaignStateLoop() { defer mgr.Done() @@ -579,26 +593,7 @@ func (mgr *electionManager) checkCampaignStateLoop() { defer ticker.Stop() for { - select { - case <-mgr.doneCh: - return - default: - } - - enabled, err := mgr.campaignIsEnabledFn() - if err != nil { - mgr.metrics.campaignCheckErrors.Inc(1) - - continue - } - newState := newCampaignState(enabled) - currState := mgr.campaignState() - if currState == newState { - continue - } - mgr.processCampaignStateChange(newState) - - // block on ticker or exit signal + mgr.checkCampaignState() select { case <-ticker.C: case <-mgr.doneCh: