Bugfix 3871 workflow concurrency (#3903)

* recursion waitgroup fix

* cleanup
dev
Mzack9999 2023-07-06 14:08:24 +02:00 committed by GitHub
parent b64d422b67
commit 305ac6a143
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 22 deletions

View File

@ -1,18 +0,0 @@
id: basic-example
info:
name: Test HTTP Template
author: pdteam
severity: info
http:
- raw:
- |+
GET / HTTP/1.1
Host: {{Hostname}}
unsafe: true
matchers:
- type: dsl
dsl:
- true

View File

@ -25,14 +25,23 @@ func (e *Engine) executeWorkflow(input *contextargs.MetaInput, w *workflows.Work
ctxArgs.MetaInput = input
ctxArgs.CookieJar = workflowCookieJar
swg := sizedwaitgroup.New(w.Options.Options.TemplateThreads)
// we can know the nesting level only at runtime, so the best we can do here is increase template threads by one unit in case it's equal to 1 to allow
// at least one subtemplate to go through, which it's idempotent to one in-flight template as the parent one is in an idle state
templateThreads := w.Options.Options.TemplateThreads
if templateThreads == 1 {
templateThreads++
}
swg := sizedwaitgroup.New(templateThreads)
for _, template := range w.Workflows {
swg.Add()
func(template *workflows.WorkflowTemplate) {
defer swg.Done()
if err := e.runWorkflowStep(template, ctxArgs, results, &swg, w); err != nil {
gologger.Warning().Msgf(workflowStepExecutionError, template.Template, err)
}
swg.Done()
}(template)
}
swg.Wait()
@ -126,10 +135,11 @@ func (e *Engine) runWorkflowStep(template *workflows.WorkflowTemplate, input *co
swg.Add()
go func(subtemplate *workflows.WorkflowTemplate) {
defer swg.Done()
if err := e.runWorkflowStep(subtemplate, input, results, swg, w); err != nil {
gologger.Warning().Msgf(workflowStepExecutionError, subtemplate.Template, err)
}
swg.Done()
}(subtemplate)
}
}

View File

@ -42,7 +42,6 @@ func Parse(filePath string, preprocessor Preprocessor, options protocols.Executo
var reader io.ReadCloser
if utils.IsURL(filePath) {
//todo:instead of creating a new client each time, a default one should be reused (same as the standard library)
// use retryablehttp (tls verification is enabled by default in the standard library)
resp, err := retryablehttp.DefaultClient().Get(filePath)
if err != nil {