Fix busylooping in case of no target providers.

merge() closes the channel that handleUpdates() reads from when there
are zero configured target providers in the configuration. In that case,
the for-select loop in handleUpdates() entered a busy loop. It should
exit when the upstream channel is closed.
This commit is contained in:
Julius Volz 2015-08-24 16:42:28 +02:00
parent 8769a75183
commit d36a7f4e6f
2 changed files with 12 additions and 2 deletions

View File

@ -171,12 +171,15 @@ func (tm *TargetManager) Run() {
tm.running = true
}
// handleTargetUpdates receives target group updates and handles them in the
// handleUpdates receives target group updates and handles them in the
// context of the given job config.
func (tm *TargetManager) handleUpdates(ch <-chan targetGroupUpdate, done <-chan struct{}) {
for {
select {
case update := <-ch:
case update, ok := <-ch:
if !ok {
return
}
if update.tg == nil {
break
}

View File

@ -376,3 +376,10 @@ func TestTargetManagerConfigUpdate(t *testing.T) {
}
}
}
func TestHandleUpdatesReturnsWhenUpdateChanIsClosed(t *testing.T) {
tm := NewTargetManager(nopAppender{})
ch := make(chan targetGroupUpdate)
close(ch)
tm.handleUpdates(ch, make(chan struct{}))
}