From 6e7b8367a61585d38392c032dda810cd8a5de4bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Alberto=20D=C3=ADaz=20Orozco?= Date: Tue, 11 Mar 2025 12:46:16 +0100 Subject: [PATCH] Exit mc mirror when errors occur if retry is disabled and it's a watch operation --- cmd/error.go | 8 ++++++++ cmd/mirror-main.go | 12 ++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cmd/error.go b/cmd/error.go index 39189e31cd..82340560c8 100644 --- a/cmd/error.go +++ b/cmd/error.go @@ -45,6 +45,14 @@ type errorMessage struct { SysInfo map[string]string `json:"sysinfo,omitempty"` } +// errorOrFatal wrapper function to call errorIf or fatalIf based on the boolean value +func errorOrFatal(useFatal bool, err *probe.Error, msg string, data ...interface{}) { + if useFatal { + fatalIf(err, msg, data...) + } + errorIf(err, msg, data...) +} + // fatalIf wrapper function which takes error and selectively prints stack frames if available on debug func fatalIf(err *probe.Error, msg string, data ...interface{}) { if err == nil { diff --git a/cmd/mirror-main.go b/cmd/mirror-main.go index dfa1b687a7..4368bb44ff 100644 --- a/cmd/mirror-main.go +++ b/cmd/mirror-main.go @@ -561,6 +561,10 @@ func (mj *mirrorJob) monitorMirrorStatus(cancel context.CancelFunc) (errDuringMi mj.status.Start() defer mj.status.Finish() + // if the operation is not retriable and is a watch operation, then + // we should exit on the first error. + useFatal := !mj.opts.isRetriable && mj.opts.isWatch + var cancelInProgress bool defer func() { @@ -595,22 +599,22 @@ func (mj *mirrorJob) monitorMirrorStatus(cancel context.CancelFunc) (errDuringMi ignoreErr = true } if !ignoreErr { - errorIf(sURLs.Error.Trace(sURLs.SourceContent.URL.String()), + errorOrFatal(useFatal, sURLs.Error.Trace(sURLs.SourceContent.URL.String()), "Failed to copy `%s`.", sURLs.SourceContent.URL) } } case sURLs.TargetContent != nil: // When sURLs.SourceContent is nil, we know that we have an error related to removing - errorIf(sURLs.Error.Trace(sURLs.TargetContent.URL.String()), + errorOrFatal(useFatal, sURLs.Error.Trace(sURLs.TargetContent.URL.String()), "Failed to remove `%s`.", sURLs.TargetContent.URL.String()) default: if strings.Contains(sURLs.Error.ToGoError().Error(), "Overwrite not allowed") { ignoreErr = true } if sURLs.ErrorCond == differInUnknown { - errorIf(sURLs.Error.Trace(), "Failed to perform mirroring") + errorOrFatal(useFatal, sURLs.Error.Trace(), "Failed to perform mirroring") } else { - errorIf(sURLs.Error.Trace(), + errorOrFatal(useFatal, sURLs.Error.Trace(), "Failed to perform mirroring, with error condition (%s)", sURLs.ErrorCond) } }