Skip to content

Commit

Permalink
Fixed deadlock in check.SetResult(). (#1619)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
greyerof authored Nov 14, 2023
1 parent afd4d6e commit ae0b030
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/checksdb/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ae0b030

Please sign in to comment.