mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-07-19 01:37:29 +00:00
fix: explicitly pass in filter to async analysis go routine (#326)
Before the filter inside the func literal was capturing the value from the outer loop. This is a subtle mistake, since in combination with running the function literal as go routine, the value of filter could have already changed at invocation time. To fix this, the filter is now passed in as an argument to the func literal. Signed-off-by: Patrick Pichler <git@patrickpichler.dev> Co-authored-by: Patrick Pichler <git@patrickpichler.dev>
This commit is contained in:
parent
5383d2e858
commit
692cd06c38
@ -161,7 +161,7 @@ func (a *Analysis) RunAnalysis() []error {
|
||||
if analyzer, ok := analyzerMap[filter]; ok {
|
||||
semaphore <- struct{}{}
|
||||
wg.Add(1)
|
||||
go func(analyzer common.IAnalyzer) {
|
||||
go func(analyzer common.IAnalyzer, filter string) {
|
||||
defer wg.Done()
|
||||
results, err := analyzer.Analyze(analyzerConfig)
|
||||
if err != nil {
|
||||
@ -173,7 +173,7 @@ func (a *Analysis) RunAnalysis() []error {
|
||||
a.Results = append(a.Results, results...)
|
||||
mutex.Unlock()
|
||||
<-semaphore
|
||||
}(analyzer)
|
||||
}(analyzer, filter)
|
||||
} else {
|
||||
errorList = append(errorList, fmt.Errorf(fmt.Sprintf("\"%s\" filter does not exist. Please run k8sgpt filters list.", filter)))
|
||||
}
|
||||
@ -190,7 +190,7 @@ func (a *Analysis) RunAnalysis() []error {
|
||||
if analyzer, ok := analyzerMap[filter]; ok {
|
||||
semaphore <- struct{}{}
|
||||
wg.Add(1)
|
||||
go func(analyzer common.IAnalyzer) {
|
||||
go func(analyzer common.IAnalyzer, filter string) {
|
||||
defer wg.Done()
|
||||
results, err := analyzer.Analyze(analyzerConfig)
|
||||
if err != nil {
|
||||
@ -202,7 +202,7 @@ func (a *Analysis) RunAnalysis() []error {
|
||||
a.Results = append(a.Results, results...)
|
||||
mutex.Unlock()
|
||||
<-semaphore
|
||||
}(analyzer)
|
||||
}(analyzer, filter)
|
||||
}
|
||||
}
|
||||
wg.Wait()
|
||||
|
Loading…
Reference in New Issue
Block a user