Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksanford committed Jul 10, 2024
1 parent 88fd150 commit a6e99ae
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions services/datamanager/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ func (svc *builtIn) propagateDataSyncConfig() error {

// startSyncScheduler starts the goroutine that calls Sync repeatedly if scheduled sync is enabled.
func (svc *builtIn) startSyncScheduler(intervalMins float64) {
cancelCtx, fn := context.WithCancel(context.Background())
cancelCtx, fn := context.WithCancel(svc.closedCtx)
svc.syncRoutineCancelFn = fn
svc.uploadData(cancelCtx, intervalMins)
}
Expand All @@ -735,11 +735,12 @@ func (svc *builtIn) uploadData(cancelCtx context.Context, intervalMins float64)
intervalMillis := 60000.0 * intervalMins
// The ticker must be created before uploadData returns to prevent race conditions between clock.Ticker and
// clock.Add in sync_test.go.
svc.syncTicker = clock.Ticker(time.Millisecond * time.Duration(intervalMillis))
tkr := clock.Ticker(time.Millisecond * time.Duration(intervalMillis))
svc.syncTicker = tkr
svc.backgroundWorkers.Add(1)
goutils.PanicCapturingGo(func() {
defer svc.backgroundWorkers.Done()
defer svc.syncTicker.Stop()
defer tkr.Stop()

for {
if err := cancelCtx.Err(); err != nil {
Expand All @@ -752,7 +753,7 @@ func (svc *builtIn) uploadData(cancelCtx context.Context, intervalMins float64)
select {
case <-cancelCtx.Done():
return
case <-svc.syncTicker.C:
case <-tkr.C:
svc.lock.Lock()
if svc.syncer != nil {
// If selective sync is disabled, sync. If it is enabled, check the condition below.
Expand Down

0 comments on commit a6e99ae

Please sign in to comment.