Skip to content

Commit b029958

Browse files
lukechampinen8maninger
authored andcommitted
syncer: Add syncing fallback
1 parent 6c96f1e commit b029958

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

syncer/syncer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,15 @@ func (s *Syncer) syncLoop(ctx context.Context) error {
686686
return err // generally fatal
687687
}
688688
p.setSynced(true)
689+
// as a fallback to ensure we never stop syncing prematurely, reset
690+
// the sync status after 60-120 seconds
691+
//
692+
// NOTE: the AfterFuncs will be garbage collected after syncLoop
693+
// returns. If we instead called defer Stop() on each of them, we
694+
// would constantly accumulate defers, leaking memory until syncLoop
695+
// returns.
696+
resyncDelay := time.Duration(60+frand.Intn(60)) * time.Second
697+
time.AfterFunc(resyncDelay, func() { p.setSynced(false) })
689698
s.log.Debug("syncing with peer", zap.Stringer("peer", p))
690699
oldTip := s.cm.Tip()
691700
oldTime := time.Now()

0 commit comments

Comments
 (0)