Discovery.Manager: close sync ch after sender() is stopped (#14465)

* close sync ch after sender() is stopped
* break if chan is closed

Signed-off-by: liyandi <littlepangdi@163.com>
Co-authored-by: liyandi <liyandi@xiaomi.com>
This commit is contained in:
Yandi Lee 2025-07-12 00:15:01 +08:00 committed by GitHub
parent f1c6fab7e1
commit 8eb445b8a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 4 deletions

View File

@ -365,8 +365,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 {
case <-m.ctx.Done():

View File

@ -254,7 +254,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

@ -127,7 +127,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 {