Skip to content

Commit

Permalink
Merge pull request #2882 from wpaulino/sync-manager-stale-syncer
Browse files Browse the repository at this point in the history
discovery: only replace stale active syncer if disconnected
  • Loading branch information
Roasbeef authored Apr 4, 2019
2 parents 2cc6687 + 00338c5 commit 3a19afe
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions discovery/sync_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -353,19 +360,20 @@ func (m *SyncManager) roundRobinHandler() {
// the set of inactive syncers.
if staleActiveSyncer.transitioned {
m.inactiveSyncers[s.cfg.peerPub] = s
} else {
// Otherwise, since the peer is disconnecting,
// we'll attempt to find a passive syncer that
// can replace it.
newActiveSyncer := m.chooseRandomSyncer(nil, false)
if newActiveSyncer != nil {
m.queueActiveSyncer(newActiveSyncer)
}
}

// Remove the internal active syncer references for this
// peer.
delete(m.pendingActiveSyncers, s.cfg.peerPub)
delete(m.activeSyncers, s.cfg.peerPub)

// We'll then attempt to find a passive syncer that can
// replace the stale active syncer.
newActiveSyncer := m.chooseRandomSyncer(nil, false)
if newActiveSyncer != nil {
m.queueActiveSyncer(newActiveSyncer)
}
m.Unlock()

// Signal to the caller that they can now proceed since
Expand Down Expand Up @@ -530,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{}{}

Expand Down

0 comments on commit 3a19afe

Please sign in to comment.