Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mutex for a safe accessing on memory between goroutines #2196

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading