Skip to content

Commit 759662f

Browse files
committed
fix: panic: close of closed channel
1 parent 98932ba commit 759662f

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

pkg/goanalysis/runner_loadingpackage.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"sync"
1515
"sync/atomic"
1616

17+
"golang.org/x/sync/errgroup"
1718
"golang.org/x/tools/go/gcexportdata"
1819
"golang.org/x/tools/go/packages"
1920

@@ -83,36 +84,28 @@ func (lp *loadingPackage) analyze(stopChan chan struct{}, loadMode LoadMode, loa
8384
return
8485
}
8586

86-
var actsWg sync.WaitGroup
87-
88-
actsWg.Add(len(lp.actions))
87+
var actsWg errgroup.Group
8988

9089
for _, act := range lp.actions {
91-
go func(act *action) {
92-
defer actsWg.Done()
93-
90+
actsWg.Go(func() error {
9491
act.waitUntilDependingAnalyzersWorked(stopChan)
9592

9693
select {
9794
case <-stopChan:
98-
return
95+
return nil
9996
default:
10097
}
10198

10299
act.analyzeSafe()
103100

104-
select {
105-
case <-stopChan:
106-
return
107-
default:
108-
if act.Err != nil {
109-
close(stopChan)
110-
}
111-
}
112-
}(act)
101+
return act.Err
102+
})
113103
}
114104

115-
actsWg.Wait()
105+
err := actsWg.Wait()
106+
if err != nil {
107+
close(stopChan)
108+
}
116109
}
117110

118111
func (lp *loadingPackage) loadFromSource(loadMode LoadMode) error {

0 commit comments

Comments
 (0)