From db7890660e0ee124b9379a35326d0c4cb62e176e Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 11 Dec 2020 16:58:36 -0800 Subject: [PATCH] fix: a crash when disk is nil, safe access on erasureDisks (#11089) fixes #11088 --- cmd/erasure-server-sets.go | 16 +++++++++++----- cmd/erasure.go | 10 +++++++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/cmd/erasure-server-sets.go b/cmd/erasure-server-sets.go index 036ed3937..add3d4fb7 100644 --- a/cmd/erasure-server-sets.go +++ b/cmd/erasure-server-sets.go @@ -99,12 +99,18 @@ func (z *erasureServerPools) GetDisksID(ids ...string) []StorageAPI { idMap[id] = struct{}{} } res := make([]StorageAPI, 0, len(idMap)) - for _, ss := range z.serverPools { - for _, disks := range ss.erasureDisks { + for _, s := range z.serverPools { + s.erasureDisksMu.RLock() + defer s.erasureDisksMu.RUnlock() + for _, disks := range s.erasureDisks { for _, disk := range disks { - id, _ := disk.GetDiskID() - if _, ok := idMap[id]; ok { - res = append(res, disk) + if disk == OfflineDisk { + continue + } + if id, _ := disk.GetDiskID(); id != "" { + if _, ok := idMap[id]; ok { + res = append(res, disk) + } } } } diff --git a/cmd/erasure.go b/cmd/erasure.go index 7b3b2dbdc..2fc168044 100644 --- a/cmd/erasure.go +++ b/cmd/erasure.go @@ -251,10 +251,14 @@ func (er erasureObjects) crawlAndGetDataUsage(ctx context.Context, buckets []Buc // Collect disks for healing. allDisks := er.getDisks() - allDiskIDs := make([]string, len(allDisks)) - for i, disk := range allDisks { + allDiskIDs := make([]string, 0, len(allDisks)) + for _, disk := range allDisks { + if disk == OfflineDisk { + // its possible that disk is OfflineDisk + continue + } id, _ := disk.GetDiskID() - allDiskIDs[i] = id + allDiskIDs = append(allDiskIDs, id) } // Load bucket totals