From 00338c5ec2a8cd3d26eaab4cc5ec08bf1f8f4c1a Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Wed, 3 Apr 2019 19:11:03 -0700 Subject: [PATCH] discovery: properly handle SyncManager shutdown signal --- discovery/sync_manager.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/discovery/sync_manager.go b/discovery/sync_manager.go index 43d95a16..11d147a8 100644 --- a/discovery/sync_manager.go +++ b/discovery/sync_manager.go @@ -286,6 +286,13 @@ func (m *SyncManager) roundRobinHandler() { current = m.nextPendingActiveSyncer() m.Unlock() for current != nil { + // Ensure we properly handle a shutdown signal. + select { + case <-m.quit: + return + default: + } + // We'll avoid performing the transition with the lock // as it can potentially stall the SyncManager due to // the syncTransitionTimeout. @@ -531,6 +538,13 @@ func (m *SyncManager) forceHistoricalSync() { candidatesChosen := make(map[routing.Vertex]struct{}) s := m.chooseRandomSyncer(candidatesChosen, true) for s != nil { + // Ensure we properly handle a shutdown signal. + select { + case <-m.quit: + return + default: + } + // Blacklist the candidate to ensure it's not chosen again. candidatesChosen[s.cfg.peerPub] = struct{}{}