mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
reduceErrs to handle context.Canceled errors (#13670)
With this change, reduceErrs will group all errors due to context cancelation as the same. e.g, Following are errors due to context cancelation seen from 3 remote disks. Their error values are different but they are all caused due to the same context cancelation. ['Post "http://minio2:9000/minio/storage/data1/v37/statvol?disk-id=101cbc99-f5d2-4a9d-b18b-97e872b3e4a7&volume=mybucket": context canceled', 'Post "http://minio3:9000/minio/storage/data1/v37/statvol?disk-id=7a84474b-a4fd-4b80-8aab-d308a587c280&volume=mybucket": context canceled', 'Post "http://minio4:9000/minio/storage/data1/v37/statvol?disk-id=d60d571a-83c8-487d-9e14-beebc94682d2&volume=mybucket": context canceled']
This commit is contained in:
parent
661b263e77
commit
367cb48096
@ -39,6 +39,11 @@ func reduceErrs(errs []error, ignoredErrs []error) (maxCount int, maxErr error)
|
|||||||
if IsErrIgnored(err, ignoredErrs...) {
|
if IsErrIgnored(err, ignoredErrs...) {
|
||||||
continue
|
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]++
|
errorCounts[err]++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +54,10 @@ func TestDiskCount(t *testing.T) {
|
|||||||
// Test for reduceErrs, reduceErr reduces collection
|
// Test for reduceErrs, reduceErr reduces collection
|
||||||
// of errors into a single maximal error with in the list.
|
// of errors into a single maximal error with in the list.
|
||||||
func TestReduceErrs(t *testing.T) {
|
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.
|
// List all of all test cases to validate various cases of reduce errors.
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
errs []error
|
errs []error
|
||||||
@ -86,6 +90,8 @@ func TestReduceErrs(t *testing.T) {
|
|||||||
{[]error{errFileNotFound, errFileNotFound, errFileNotFound,
|
{[]error{errFileNotFound, errFileNotFound, errFileNotFound,
|
||||||
errFileNotFound, errFileNotFound, nil, nil, nil, nil, nil},
|
errFileNotFound, errFileNotFound, nil, nil, 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.
|
// Validates list of all the testcases for returning valid errors.
|
||||||
for i, testCase := range testCases {
|
for i, testCase := range testCases {
|
||||||
|
Loading…
Reference in New Issue
Block a user