fix: mirror active-active and race condition (#5234)

This commit is contained in:
Shreyas Mali
2025-07-19 07:45:24 -07:00
committed by GitHub
parent 2676e50bc1
commit e5d2270535
+8 -3
View File
@@ -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 {