mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-12-01 21:44:23 +01:00
limit goroutines on file scanning to avoid pegging them cores (#759)
This commit is contained in:
1 parent
705595aaf6
commit
1c6c26eca8
1 file changed
+5
@@ -20,6 +20,7 @@ func FromFiles(source string, cfg config.Config, outputOptions Options) ([]repor
|
|||||||
findings []report.Finding
|
findings []report.Finding
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
)
|
)
|
||||||
|
concurrentGoroutines := make(chan struct{}, 4)
|
||||||
g, _ := errgroup.WithContext(context.Background())
|
g, _ := errgroup.WithContext(context.Background())
|
||||||
paths := make(chan string)
|
paths := make(chan string)
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
@@ -41,12 +42,15 @@ func FromFiles(source string, cfg config.Config, outputOptions Options) ([]repor
|
|||||||
for pa := range paths {
|
for pa := range paths {
|
||||||
p := pa
|
p := pa
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
|
concurrentGoroutines <- struct{}{}
|
||||||
b, err := os.ReadFile(p)
|
b, err := os.ReadFile(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
<-concurrentGoroutines
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !godocutil.IsText(b) {
|
if !godocutil.IsText(b) {
|
||||||
|
<-concurrentGoroutines
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
fis := DetectFindings(cfg, b, p, "")
|
fis := DetectFindings(cfg, b, p, "")
|
||||||
@@ -65,6 +69,7 @@ func FromFiles(source string, cfg config.Config, outputOptions Options) ([]repor
|
|||||||
findings = append(findings, fi)
|
findings = append(findings, fi)
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
}
|
}
|
||||||
|
<-concurrentGoroutines
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user