Skip to content

Commit e5d2270

Browse files
fix: mirror active-active and race condition (#5234)
1 parent 2676e50 commit e5d2270

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

cmd/mirror-main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,10 @@ func (mj *mirrorJob) mirror(ctx context.Context) bool {
873873
var wg sync.WaitGroup
874874
ctx, cancel := context.WithCancel(ctx)
875875

876+
doneCh := make(chan struct{})
877+
876878
// Starts watcher loop for watching for new events.
877-
if mj.opts.isWatch {
879+
if mj.opts.isWatch || mj.opts.activeActive {
878880
wg.Add(1)
879881
go func() {
880882
defer wg.Done()
@@ -895,9 +897,12 @@ func (mj *mirrorJob) mirror(ctx context.Context) bool {
895897
wg.Wait()
896898
mj.parallel.stopAndWait()
897899
close(mj.statusCh)
900+
close(doneCh)
898901
}()
899902

900-
return mj.monitorMirrorStatus(cancel)
903+
ret := mj.monitorMirrorStatus(cancel)
904+
<-doneCh
905+
return ret
901906
}
902907

903908
func newMirrorJob(srcURL, dstURL string, opts mirrorOptions) *mirrorJob {
@@ -1140,7 +1145,7 @@ func runMirror(ctx context.Context, srcURL, dstURL string, cli *cli.Context, enc
11401145
}
11411146
}
11421147

1143-
if mj.opts.isWatch {
1148+
if mj.opts.isWatch || mj.opts.activeActive {
11441149
// monitor mode will watch the source folders for changes,
11451150
// and queue them for copying.
11461151
if err := mj.watchURL(ctx, srcClt); err != nil {

0 commit comments

Comments
 (0)