limit number of goroutines for historic scanning as well (#761)

This commit is contained in:
Zachary Rice authored and GitHub committed 2022-01-07 08:58:47 -06:00
1 parent 44d7d89e19
commit 801d44a6e4
3 files changed
+13 -7

No files matched your search

+5 -5
View File
@@ -20,7 +20,7 @@ func FromFiles(source string, cfg config.Config, outputOptions Options) ([]repor
findings []report.Finding
mu sync.Mutex
)
concurrentGoroutines := make(chan struct{}, 4)
concurrentGoroutines := make(chan struct{}, MAXGOROUTINES)
g, _ := errgroup.WithContext(context.Background())
paths := make(chan string)
g.Go(func() error {
@@ -41,16 +41,17 @@ func FromFiles(source string, cfg config.Config, outputOptions Options) ([]repor
})
for pa := range paths {
p := pa
concurrentGoroutines <- struct{}{}
g.Go(func() error {
concurrentGoroutines <- struct{}{}
defer func() {
<-concurrentGoroutines
}()
b, err := os.ReadFile(p)
if err != nil {
<-concurrentGoroutines
return err
}
if !godocutil.IsText(b) {
<-concurrentGoroutines
return nil
}
fis := DetectFindings(cfg, b, p, "")
@@ -69,7 +70,6 @@ func FromFiles(source string, cfg config.Config, outputOptions Options) ([]repor
findings = append(findings, fi)
mu.Unlock()
}
<-concurrentGoroutines
return nil
})
}