From a7e2a1a38ba7ab0bc7d95c6edf58244804ecd7c5 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Fri, 2 Jul 2021 11:19:56 -0700 Subject: [PATCH] fix: two different scanner update races (#12615) --- cmd/erasure.go | 6 +++--- cmd/storage-rest-server.go | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/erasure.go b/cmd/erasure.go index 92a8d9781..d2c200e29 100644 --- a/cmd/erasure.go +++ b/cmd/erasure.go @@ -484,11 +484,11 @@ func (er erasureObjects) nsScanner(ctx context.Context, buckets []BucketInfo, bf updates := make(chan dataUsageEntry, 1) var wg sync.WaitGroup wg.Add(1) - go func() { + go func(name string) { defer wg.Done() for update := range updates { bucketResults <- dataUsageEntryInfo{ - Name: cache.Info.Name, + Name: name, Parent: dataUsageRoot, Entry: update, } @@ -496,7 +496,7 @@ func (er erasureObjects) nsScanner(ctx context.Context, buckets []BucketInfo, bf console.Debugln("bucket", bucket.Name, "got update", update) } } - }() + }(cache.Info.Name) // Calc usage before := cache.Info.LastUpdate diff --git a/cmd/storage-rest-server.go b/cmd/storage-rest-server.go index 872a14a8a..ba71454d7 100644 --- a/cmd/storage-rest-server.go +++ b/cmd/storage-rest-server.go @@ -188,6 +188,7 @@ func (s *storageRESTServer) NSScannerHandler(w http.ResponseWriter, r *http.Requ defer wg.Done() for update := range updates { // Write true bool to indicate update. + var err error if err = respW.WriteBool(true); err == nil { err = update.EncodeMsg(respW) } @@ -211,6 +212,10 @@ func (s *storageRESTServer) NSScannerHandler(w http.ResponseWriter, r *http.Requ if err = respW.WriteBool(false); err == nil { err = usageInfo.EncodeMsg(respW) } + if err != nil { + resp.CloseWithError(err) + return + } resp.CloseWithError(respW.Flush()) }