Skip to content

Commit 1eef07d

Browse files
committed
fix: Data race when reporting progress
1 parent f9eeb4c commit 1eef07d

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

cli/cmd/sync_v3.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ func syncConnectionV3(ctx context.Context, syncOptions syncV3Options) (syncErr e
381381
if err != nil {
382382
return fmt.Errorf("failed to parse sync run ID: %w", err)
383383
}
384-
remoteProgressReporter = godebouncer.NewWithOptions(godebouncer.WithTimeDuration(10*time.Second), godebouncer.WithTriggered(func() {
384+
385+
triggerFunc := func() {
385386
totals := sourceClient.Metrics()
386387
for i := range destinationsClients {
387388
m := destinationsClients[i].Metrics()
@@ -414,8 +415,13 @@ func syncConnectionV3(ctx context.Context, syncOptions syncV3Options) (syncErr e
414415
if res.StatusCode() != http.StatusNoContent {
415416
log.Warn().Str("status", res.Status()).Int("code", res.StatusCode()).Msg("Failed to send sync progress to API")
416417
}
417-
}), godebouncer.WithOptions(godebouncer.Options{Trailing: true, Leading: true}))
418-
defer remoteProgressReporter.Cancel()
418+
}
419+
remoteProgressReporter = godebouncer.NewWithOptions(godebouncer.WithTimeDuration(10*time.Second), godebouncer.WithTriggered(triggerFunc), godebouncer.WithOptions(godebouncer.Options{Trailing: true, Leading: true}))
420+
421+
defer func() {
422+
remoteProgressReporter.Cancel()
423+
triggerFunc()
424+
}()
419425
}
420426

421427
// Transformers can change table names. We need to keep track of table name changes
@@ -742,10 +748,6 @@ func syncConnectionV3(ctx context.Context, syncOptions syncV3Options) (syncErr e
742748
Str("result", msg).
743749
Msg("Sync summary")
744750

745-
if remoteProgressReporter != nil {
746-
remoteProgressReporter.SendSignal()
747-
<-remoteProgressReporter.Done()
748-
}
749751
return nil
750752
}
751753

0 commit comments

Comments
 (0)