@@ -286,6 +286,13 @@ func (m *SyncManager) roundRobinHandler() {
286
286
current = m .nextPendingActiveSyncer ()
287
287
m .Unlock ()
288
288
for current != nil {
289
+ // Ensure we properly handle a shutdown signal.
290
+ select {
291
+ case <- m .quit :
292
+ return
293
+ default :
294
+ }
295
+
289
296
// We'll avoid performing the transition with the lock
290
297
// as it can potentially stall the SyncManager due to
291
298
// the syncTransitionTimeout.
@@ -353,19 +360,20 @@ func (m *SyncManager) roundRobinHandler() {
353
360
// the set of inactive syncers.
354
361
if staleActiveSyncer .transitioned {
355
362
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
+ }
356
371
}
357
372
358
373
// Remove the internal active syncer references for this
359
374
// peer.
360
375
delete (m .pendingActiveSyncers , s .cfg .peerPub )
361
376
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
- }
369
377
m .Unlock ()
370
378
371
379
// Signal to the caller that they can now proceed since
@@ -530,6 +538,13 @@ func (m *SyncManager) forceHistoricalSync() {
530
538
candidatesChosen := make (map [routing.Vertex ]struct {})
531
539
s := m .chooseRandomSyncer (candidatesChosen , true )
532
540
for s != nil {
541
+ // Ensure we properly handle a shutdown signal.
542
+ select {
543
+ case <- m .quit :
544
+ return
545
+ default :
546
+ }
547
+
533
548
// Blacklist the candidate to ensure it's not chosen again.
534
549
candidatesChosen [s .cfg .peerPub ] = struct {}{}
535
550
0 commit comments