Skip to content

Commit c18f3ff

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

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ require (
134134
go.augendre.info/fatcontext v0.8.0
135135
go.uber.org/automaxprocs v1.6.0
136136
golang.org/x/mod v0.25.0
137+
golang.org/x/sync v0.15.0
137138
golang.org/x/sys v0.33.0
138139
golang.org/x/tools v0.34.0
139140
gopkg.in/yaml.v3 v3.0.1
@@ -213,7 +214,6 @@ require (
213214
go.uber.org/zap v1.24.0 // indirect
214215
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
215216
golang.org/x/exp/typeparams v0.0.0-20250210185358-939b2ce775ac // indirect
216-
golang.org/x/sync v0.15.0 // indirect
217217
golang.org/x/text v0.26.0 // indirect
218218
google.golang.org/protobuf v1.36.6 // indirect
219219
gopkg.in/ini.v1 v1.67.0 // indirect

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)