break if chan is closed

Signed-off-by: liyandi <littlepangdi@163.com>
This commit is contained in:
liyandi 2024-07-12 18:12:20 +08:00
parent 8335071154
commit 658e684644
3 changed files with 12 additions and 3 deletions

View file

@ -203,7 +203,10 @@ func (m *Manager) updater(ctx context.Context, p *provider, updates chan []*targ
func (m *Manager) sender() {
ticker := time.NewTicker(m.updatert)
defer ticker.Stop()
defer func() {
ticker.Stop()
close(m.syncCh)
}()
for {
select {

View file

@ -358,7 +358,10 @@ func (n *Manager) targetUpdateLoop(tsets <-chan map[string][]*targetgroup.Group)
select {
case <-n.stopRequested:
return
case ts := <-tsets:
case ts, ok := <-tsets:
if !ok {
break
}
n.reload(ts)
}
}

View file

@ -119,7 +119,10 @@ func (m *Manager) Run(tsets <-chan map[string][]*targetgroup.Group) error {
go m.reloader()
for {
select {
case ts := <-tsets:
case ts, ok := <-tsets:
if !ok {
break
}
m.updateTsets(ts)
select {