Skip to content

Commit

Permalink
limit goroutines on file scanning to avoid pegging them cores (gitlea…
Browse files Browse the repository at this point in the history
  • Loading branch information
zricethezav authored Dec 22, 2021
1 parent 705595a commit aae23ac
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions detect/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func FromFiles(source string, cfg config.Config, outputOptions Options) ([]repor
findings []report.Finding
mu sync.Mutex
)
concurrentGoroutines := make(chan struct{}, 4)
g, _ := errgroup.WithContext(context.Background())
paths := make(chan string)
g.Go(func() error {
Expand All @@ -41,12 +42,15 @@ func FromFiles(source string, cfg config.Config, outputOptions Options) ([]repor
for pa := range paths {
p := pa
g.Go(func() error {
concurrentGoroutines <- struct{}{}
b, err := os.ReadFile(p)
if err != nil {
<-concurrentGoroutines
return err
}

if !godocutil.IsText(b) {
<-concurrentGoroutines
return nil
}
fis := DetectFindings(cfg, b, p, "")
Expand All @@ -65,6 +69,7 @@ func FromFiles(source string, cfg config.Config, outputOptions Options) ([]repor
findings = append(findings, fi)
mu.Unlock()
}
<-concurrentGoroutines
return nil
})
}
Expand Down

0 comments on commit aae23ac

Please sign in to comment.