From e5d227053520449d5140013807cd7ac0e878a478 Mon Sep 17 00:00:00 2001 From: Shreyas Mali <83450905+toastsandwich@users.noreply.github.com> Date: Sat, 19 Jul 2025 20:15:24 +0530 Subject: [PATCH] fix: mirror active-active and race condition (#5234) --- cmd/mirror-main.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/mirror-main.go b/cmd/mirror-main.go index b1204e44..41b99cbf 100644 --- a/cmd/mirror-main.go +++ b/cmd/mirror-main.go @@ -873,8 +873,10 @@ func (mj *mirrorJob) mirror(ctx context.Context) bool { var wg sync.WaitGroup ctx, cancel := context.WithCancel(ctx) + doneCh := make(chan struct{}) + // Starts watcher loop for watching for new events. - if mj.opts.isWatch { + if mj.opts.isWatch || mj.opts.activeActive { wg.Add(1) go func() { defer wg.Done() @@ -895,9 +897,12 @@ func (mj *mirrorJob) mirror(ctx context.Context) bool { wg.Wait() mj.parallel.stopAndWait() close(mj.statusCh) + close(doneCh) }() - return mj.monitorMirrorStatus(cancel) + ret := mj.monitorMirrorStatus(cancel) + <-doneCh + return ret } func newMirrorJob(srcURL, dstURL string, opts mirrorOptions) *mirrorJob { @@ -1140,7 +1145,7 @@ func runMirror(ctx context.Context, srcURL, dstURL string, cli *cli.Context, enc } } - if mj.opts.isWatch { + if mj.opts.isWatch || mj.opts.activeActive { // monitor mode will watch the source folders for changes, // and queue them for copying. if err := mj.watchURL(ctx, srcClt); err != nil {