mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 13:14:22 +01:00
limit number of goroutines for historic scanning as well (#761)
This commit is contained in:
1 parent
44d7d89e19
commit
801d44a6e4
3 files changed
+13
-7
No files matched your search
+5
-5
@@ -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
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user