Skip to content

Commit 3a19afe

Browse files
authored
Merge pull request #2882 from wpaulino/sync-manager-stale-syncer
discovery: only replace stale active syncer if disconnected
2 parents 2cc6687 + 00338c5 commit 3a19afe

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

discovery/sync_manager.go

+22-7
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,13 @@ func (m *SyncManager) roundRobinHandler() {
286286
current = m.nextPendingActiveSyncer()
287287
m.Unlock()
288288
for current != nil {
289+
// Ensure we properly handle a shutdown signal.
290+
select {
291+
case <-m.quit:
292+
return
293+
default:
294+
}
295+
289296
// We'll avoid performing the transition with the lock
290297
// as it can potentially stall the SyncManager due to
291298
// the syncTransitionTimeout.
@@ -353,19 +360,20 @@ func (m *SyncManager) roundRobinHandler() {
353360
// the set of inactive syncers.
354361
if staleActiveSyncer.transitioned {
355362
m.inactiveSyncers[s.cfg.peerPub] = s
363+
} else {
364+
// Otherwise, since the peer is disconnecting,
365+
// we'll attempt to find a passive syncer that
366+
// can replace it.
367+
newActiveSyncer := m.chooseRandomSyncer(nil, false)
368+
if newActiveSyncer != nil {
369+
m.queueActiveSyncer(newActiveSyncer)
370+
}
356371
}
357372

358373
// Remove the internal active syncer references for this
359374
// peer.
360375
delete(m.pendingActiveSyncers, s.cfg.peerPub)
361376
delete(m.activeSyncers, s.cfg.peerPub)
362-
363-
// We'll then attempt to find a passive syncer that can
364-
// replace the stale active syncer.
365-
newActiveSyncer := m.chooseRandomSyncer(nil, false)
366-
if newActiveSyncer != nil {
367-
m.queueActiveSyncer(newActiveSyncer)
368-
}
369377
m.Unlock()
370378

371379
// Signal to the caller that they can now proceed since
@@ -530,6 +538,13 @@ func (m *SyncManager) forceHistoricalSync() {
530538
candidatesChosen := make(map[routing.Vertex]struct{})
531539
s := m.chooseRandomSyncer(candidatesChosen, true)
532540
for s != nil {
541+
// Ensure we properly handle a shutdown signal.
542+
select {
543+
case <-m.quit:
544+
return
545+
default:
546+
}
547+
533548
// Blacklist the candidate to ensure it's not chosen again.
534549
candidatesChosen[s.cfg.peerPub] = struct{}{}
535550

0 commit comments

Comments
 (0)