From 6ecc98fddbfb6ffa6e31dc79b0acac407154f9ac Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 25 Apr 2020 19:48:07 -0700 Subject: [PATCH] fix: crash in metrics handler when some disks are offline (#9450) Fixes #9449 --- cmd/xl-v1.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cmd/xl-v1.go b/cmd/xl-v1.go index 6bba669f0..7cbe0014b 100644 --- a/cmd/xl-v1.go +++ b/cmd/xl-v1.go @@ -175,20 +175,21 @@ func getStorageInfo(disks []StorageAPI, endpoints Endpoints) StorageInfo { // StorageInfo - returns underlying storage statistics. func (xl xlObjects) StorageInfo(ctx context.Context, local bool) StorageInfo { - var endpoints = xl.endpoints - var disks []StorageAPI - if !local { - disks = xl.getDisks() - } else { - for i, d := range xl.getDisks() { - if endpoints[i].IsLocal && d.Hostname() == "" { - // Append this local disk since local flag is true - disks = append(disks, d) + disks := xl.getDisks() + if local { + var localDisks []StorageAPI + for i, disk := range disks { + if disk != nil { + if xl.endpoints[i].IsLocal && disk.Hostname() == "" { + // Append this local disk since local flag is true + localDisks = append(localDisks, disk) + } } } + disks = localDisks } - return getStorageInfo(disks, endpoints) + return getStorageInfo(disks, xl.endpoints) } // GetMetrics - is not implemented and shouldn't be called.