From ae0b030cf3a1faaaf1f6678985fb1610642e40b0 Mon Sep 17 00:00:00 2001 From: Gonzalo Reyero Ferreras <87083379+greyerof@users.noreply.github.com> Date: Tue, 14 Nov 2023 16:56:17 +0100 Subject: [PATCH] Fixed deadlock in check.SetResult(). (#1619) SetResult() was calling check.SetResultFailed() inside, which locks the mutex again, resulting in a deadlock. Also, the check will be implicitly "skipped" in case both compliant and non-compliant objects lists are empty. --- pkg/checksdb/check.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/checksdb/check.go b/pkg/checksdb/check.go index f45974496..07269de59 100644 --- a/pkg/checksdb/check.go +++ b/pkg/checksdb/check.go @@ -110,12 +110,22 @@ func (check *Check) SetResult(compliantObjects, nonCompliantObjects []*testhelpe logrus.Errorf("Failed to get result objects string for check %s: %v", check.ID, err) } + check.CapturedOutput = resultObjectsStr + // If an error/panic happened before, do not change the result. - if check.Result != CheckResultError && len(nonCompliantObjects) > 0 { - check.SetResultFailed(resultObjectsStr) + if check.Result == CheckResultError { + return } - check.CapturedOutput = resultObjectsStr + if len(nonCompliantObjects) > 0 { + check.Result = CheckResultFailed + check.FailureReason = resultObjectsStr + } else if len(compliantObjects) == 0 { + // Mark this check as skipped. + logrus.Warnf("Check %s marked as skipped as both compliant and non-compliant objects lists are empty.", check.ID) + check.FailureReason = "Compliant and non-compliant objects lists are empty." + check.Result = CheckResultSkipped + } } func (check *Check) SetResultFailed(reason string) {