File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -686,6 +686,15 @@ func (s *Syncer) syncLoop(ctx context.Context) error {
686
686
return err // generally fatal
687
687
}
688
688
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 ) })
689
698
s .log .Debug ("syncing with peer" , zap .Stringer ("peer" , p ))
690
699
oldTip := s .cm .Tip ()
691
700
oldTime := time .Now ()
You can’t perform that action at this time.
0 commit comments