From c7c7847b6f12fa11821ab2927ba4b8d8888d9f07 Mon Sep 17 00:00:00 2001 From: Jinwook Jeong Date: Sat, 9 Apr 2022 01:03:54 +0900 Subject: [PATCH] Fix discovery managers to be properly cancelled Signed-off-by: Jinwook Jeong --- discovery/legacymanager/manager.go | 8 +++----- discovery/manager.go | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/discovery/legacymanager/manager.go b/discovery/legacymanager/manager.go index 7a3d6b3b8..2c8ba18a0 100644 --- a/discovery/legacymanager/manager.go +++ b/discovery/legacymanager/manager.go @@ -140,11 +140,9 @@ type Manager struct { // Run starts the background processing func (m *Manager) Run() error { go m.sender() - for range m.ctx.Done() { - m.cancelDiscoverers() - return m.ctx.Err() - } - return nil + <-m.ctx.Done() + m.cancelDiscoverers() + return m.ctx.Err() } // SyncCh returns a read only channel used by all the clients to receive target updates. diff --git a/discovery/manager.go b/discovery/manager.go index 088b9722c..6747c5690 100644 --- a/discovery/manager.go +++ b/discovery/manager.go @@ -166,11 +166,9 @@ type Manager struct { // Run starts the background processing. func (m *Manager) Run() error { go m.sender() - for range m.ctx.Done() { - m.cancelDiscoverers() - return m.ctx.Err() - } - return nil + <-m.ctx.Done() + m.cancelDiscoverers() + return m.ctx.Err() } // SyncCh returns a read only channel used by all the clients to receive target updates.