Skip to content

Commit aae23ac

Browse files
authored
limit goroutines on file scanning to avoid pegging them cores (#759)
1 parent 705595a commit aae23ac

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

detect/files.go

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func FromFiles(source string, cfg config.Config, outputOptions Options) ([]repor
2020
findings []report.Finding
2121
mu sync.Mutex
2222
)
23+
concurrentGoroutines := make(chan struct{}, 4)
2324
g, _ := errgroup.WithContext(context.Background())
2425
paths := make(chan string)
2526
g.Go(func() error {
@@ -41,12 +42,15 @@ func FromFiles(source string, cfg config.Config, outputOptions Options) ([]repor
4142
for pa := range paths {
4243
p := pa
4344
g.Go(func() error {
45+
concurrentGoroutines <- struct{}{}
4446
b, err := os.ReadFile(p)
4547
if err != nil {
48+
<-concurrentGoroutines
4649
return err
4750
}
4851

4952
if !godocutil.IsText(b) {
53+
<-concurrentGoroutines
5054
return nil
5155
}
5256
fis := DetectFindings(cfg, b, p, "")
@@ -65,6 +69,7 @@ func FromFiles(source string, cfg config.Config, outputOptions Options) ([]repor
6569
findings = append(findings, fi)
6670
mu.Unlock()
6771
}
72+
<-concurrentGoroutines
6873
return nil
6974
})
7075
}

0 commit comments

Comments
 (0)