From 67ce559b12c9439043a0a518dd8edeb40f542adf Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 29 Nov 2023 15:34:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=A6=82=E8=A7=88=E9=A1=B5=E7=A3=81?= =?UTF-8?q?=E7=9B=98=E4=BF=A1=E6=81=AF=E8=8E=B7=E5=8F=96=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=94=81=20(#3100)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/dashboard.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/backend/app/service/dashboard.go b/backend/app/service/dashboard.go index 1a23d4d05..7ab95c412 100644 --- a/backend/app/service/dashboard.go +++ b/backend/app/service/dashboard.go @@ -209,7 +209,10 @@ func loadDiskInfo() []dto.DiskInfo { mounts = append(mounts, diskInfo{Type: fields[1], Device: fields[0], Mount: fields[6]}) } - var wg sync.WaitGroup + var ( + wg sync.WaitGroup + mu sync.Mutex + ) wg.Add(len(mounts)) for i := 0; i < len(mounts); i++ { go func(timeoutCh <-chan time.Time, mount diskInfo) { @@ -221,11 +224,17 @@ func loadDiskInfo() []dto.DiskInfo { itemData.Device = mount.Device select { case <-timeoutCh: + mu.Lock() datas = append(datas, itemData) + mu.Unlock() global.LOG.Errorf("load disk info from %s failed, err: timeout", mount.Mount) default: state, err := disk.Usage(mount.Mount) if err != nil { + mu.Lock() + datas = append(datas, itemData) + mu.Unlock() + global.LOG.Errorf("load disk info from %s failed, err: %v", mount.Mount, err) return } itemData.Total = state.Total @@ -236,7 +245,9 @@ func loadDiskInfo() []dto.DiskInfo { itemData.InodesUsed = state.InodesUsed itemData.InodesFree = state.InodesFree itemData.InodesUsedPercent = state.InodesUsedPercent + mu.Lock() datas = append(datas, itemData) + mu.Unlock() } }(time.After(5*time.Second), mounts[i]) }