Skip to content

Commit

Permalink
add mutex for a safe accessing on memory between goroutines: (#2196)
Browse files Browse the repository at this point in the history
  • Loading branch information
Omarabdul3ziz authored Feb 14, 2024
1 parent 0243200 commit 08cd092
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/diagnostics/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,30 @@ func (m *DiagnosticsManager) GetSystemDiagnostics(ctx context.Context) (Diagnost
}

var wg sync.WaitGroup
for _, module := range Modules {
var mut sync.Mutex
var hasError bool

for _, module := range Modules {
wg.Add(1)
go func(module string) {
defer wg.Done()
report := m.getModuleStatus(ctx, module)

mut.Lock()
defer mut.Unlock()

results.ZosModules[module] = report

if report.Err != nil {
results.SystemStatusOk = false
hasError = true
}
}(module)

}

wg.Wait()

results.SystemStatusOk = !hasError
results.Online = m.isOnline(ctx)

return results, nil
Expand Down
5 changes: 5 additions & 0 deletions pkg/perf/networkhealth/networkhealth.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@ func (t *NetworkHealthTask) Run(ctx context.Context) (interface{}, error) {
reports := []ServiceStatus{}

var wg sync.WaitGroup
var mut sync.Mutex
for _, serviceUrl := range servicesUrl {
wg.Add(1)
go func(serviceUrl string) {
defer wg.Done()
report := getNetworkReport(ctx, serviceUrl)

mut.Lock()
defer mut.Unlock()

reports = append(reports, report)
}(serviceUrl)
}
Expand Down

0 comments on commit 08cd092

Please sign in to comment.