From 30dcc5015c45aaf9bcd3b2e0cf2e43f8eda3e188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20R=C3=B6hrs?= Date: Wed, 25 Nov 2026 13:10:35 +0100 Subject: [PATCH] fix(heal): do not panic when CheckParts returns no result MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A remote CheckParts stream that ends without a response and without an error (e.g. the grid mux is closed during a disconnect) made storageRESTClient.CheckParts return (nil, nil). checkObjectWithAllParts then dereferenced the nil response and crashed the whole server process. Return grid.ErrDisconnected from the client in that case, and treat a nil or short per-part result as an unreachable drive in checkObjectWithAllParts. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Lucas Röhrs --- cmd/erasure-healing-common.go | 6 ++++ cmd/erasure-healing-common_test.go | 50 ++++++++++++++++++++++++++++++ cmd/storage-rest-client.go | 6 ++++ 3 files changed, 62 insertions(+) diff --git a/cmd/erasure-healing-common.go b/cmd/erasure-healing-common.go index 0bde3107d..04cb38020 100644 --- a/cmd/erasure-healing-common.go +++ b/cmd/erasure-healing-common.go @@ -420,6 +420,12 @@ func checkObjectWithAllParts(ctx context.Context, onlineDisks []StorageAPI, part default: verifyResp, verifyErr = onlineDisk.CheckParts(ctx, bucket, object, meta) } + if verifyErr == nil && (verifyResp == nil || len(verifyResp.Results) < len(latestMeta.Parts)) { + // A drive that returned no usable per-part result cannot vouch + // for its parts; treat it like an unreachable drive instead of + // dereferencing a nil or short response. + verifyErr = errDiskNotFound + } for p := range latestMeta.Parts { if verifyErr != nil { diff --git a/cmd/erasure-healing-common_test.go b/cmd/erasure-healing-common_test.go index 04909b2df..317ca1cee 100644 --- a/cmd/erasure-healing-common_test.go +++ b/cmd/erasure-healing-common_test.go @@ -772,3 +772,53 @@ func TestCommonParities(t *testing.T) { } } } + +// checkPartsResultDisk returns a programmed CheckParts/VerifyFile result. +// All other StorageAPI methods are unimplemented and panic if called. +type checkPartsResultDisk struct { + StorageAPI + resp *CheckPartsResp + err error +} + +func (d *checkPartsResultDisk) CheckParts(context.Context, string, string, FileInfo) (*CheckPartsResp, error) { + return d.resp, d.err +} + +func (d *checkPartsResultDisk) VerifyFile(context.Context, string, string, FileInfo) (*CheckPartsResp, error) { + return d.resp, d.err +} + +// A drive whose CheckParts/VerifyFile returns no error but also no (or a +// short) per-part result, e.g. a remote stream that ended without a response, +// must be reported as unreachable instead of crashing the heal. +func TestCheckObjectWithAllPartsMissingResult(t *testing.T) { + for _, scanMode := range []madmin.HealScanMode{madmin.HealNormalScan, madmin.HealDeepScan} { + t.Run(fmt.Sprintf("scanMode=%d", scanMode), func(t *testing.T) { + meta := nativeAuditMetadata() + full := &CheckPartsResp{Results: []int{checkPartSuccess, checkPartSuccess}} + disks := []StorageAPI{ + &checkPartsResultDisk{resp: nil}, // (nil, nil) + &checkPartsResultDisk{resp: &CheckPartsResp{Results: []int{checkPartSuccess}}}, // short result + &checkPartsResultDisk{resp: full}, + &checkPartsResultDisk{resp: full}, + } + errs := make([]error, len(disks)) + + dataErrsByDisk, _ := checkObjectWithAllParts(t.Context(), disks, meta, errs, meta[0], + false, "bucket", "object", scanMode) + + for i := range disks { + for p, got := range dataErrsByDisk[i] { + want := checkPartSuccess + if i < 2 { + want = checkPartDiskNotFound + } + if got != want { + t.Errorf("disk %d part %d: got %d, want %d", i, p, got, want) + } + } + } + }) + } +} diff --git a/cmd/storage-rest-client.go b/cmd/storage-rest-client.go index 0ba573847..fb750adf1 100644 --- a/cmd/storage-rest-client.go +++ b/cmd/storage-rest-client.go @@ -480,6 +480,12 @@ func (client *storageRESTClient) CheckParts(ctx context.Context, volume string, resp = r return nil }) + if err == nil && resp == nil { + // The stream ended without a response and without an error, + // e.g. when the mux was closed during a disconnect. Never + // return (nil, nil): callers rely on resp being set on success. + err = grid.ErrDisconnected + } return resp, toStorageErr(err) }