diff --git a/cmd/erasure-metadata-utils.go b/cmd/erasure-metadata-utils.go index 16ae8118b..ef28834ef 100644 --- a/cmd/erasure-metadata-utils.go +++ b/cmd/erasure-metadata-utils.go @@ -39,6 +39,11 @@ func reduceErrs(errs []error, ignoredErrs []error) (maxCount int, maxErr error) if IsErrIgnored(err, ignoredErrs...) { continue } + // Errors due to context cancelation may be wrapped - group them by context.Canceled. + if errors.Is(err, context.Canceled) { + errorCounts[context.Canceled]++ + continue + } errorCounts[err]++ } diff --git a/cmd/erasure-metadata-utils_test.go b/cmd/erasure-metadata-utils_test.go index 4d24b0673..a64976481 100644 --- a/cmd/erasure-metadata-utils_test.go +++ b/cmd/erasure-metadata-utils_test.go @@ -54,6 +54,10 @@ func TestDiskCount(t *testing.T) { // Test for reduceErrs, reduceErr reduces collection // of errors into a single maximal error with in the list. func TestReduceErrs(t *testing.T) { + canceledErrs := make([]error, 0, 5) + for i := 0; i < 5; i++ { + canceledErrs = append(canceledErrs, fmt.Errorf("error %d: %w", i, context.Canceled)) + } // List all of all test cases to validate various cases of reduce errors. testCases := []struct { errs []error @@ -86,6 +90,8 @@ func TestReduceErrs(t *testing.T) { {[]error{errFileNotFound, errFileNotFound, errFileNotFound, errFileNotFound, errFileNotFound, nil, nil, nil, nil, nil}, nil, nil}, + // Checks if wrapped context cancelation errors are grouped as one. + {canceledErrs, nil, context.Canceled}, } // Validates list of all the testcases for returning valid errors. for i, testCase := range testCases {