Skip to content

Conversation

@dwisiswant0
Copy link
Member

@dwisiswant0 dwisiswant0 commented Sep 23, 2025

Proposed changes

add missing go keyword to anonymous funcs that
were intended to run as goroutines but were
executing synchronously instead.

Fixes #6492

Proof

this PR

$ go test -v ./pkg/protocols/file/ ./pkg/core/ -run "Test(FileProtocol|Workflows)ConcurrentExecution"
=== RUN   TestFileProtocolConcurrentExecution
    request_test.go:201: Total execution time: 10.474836ms
    request_test.go:202: Files processed: 5
    request_test.go:203: Results returned: 5
--- PASS: TestFileProtocolConcurrentExecution (0.22s)
PASS
ok  	github.com/projectdiscovery/nuclei/v3/pkg/protocols/file	(cached)
=== RUN   TestWorkflowsConcurrentExecution
    workflow_execute_test.go:236: Workflow execution completed in: 40.360762ms
    workflow_execute_test.go:237: Templates executed: 4
    workflow_execute_test.go:238: Execution times collected: 4
--- PASS: TestWorkflowsConcurrentExecution (0.04s)
PASS
ok  	github.com/projectdiscovery/nuclei/v3/pkg/core	(cached)

dev

Note

Apply bcf7a90 patch first.

$ go test -v ./pkg/protocols/file/ ./pkg/core/ -run "Test(FileProtocol|Workflows)ConcurrentExecution"
=== RUN   TestFileProtocolConcurrentExecution
    request_test.go:201: Total execution time: 51.871803ms
    request_test.go:202: Files processed: 5
    request_test.go:203: Results returned: 5
--- PASS: TestFileProtocolConcurrentExecution (0.30s)
PASS
ok  	github.com/projectdiscovery/nuclei/v3/pkg/protocols/file	1.340s
=== RUN   TestWorkflowsConcurrentExecution
    workflow_execute_test.go:236: Workflow execution completed in: 161.506765ms
    workflow_execute_test.go:237: Templates executed: 4
    workflow_execute_test.go:238: Execution times collected: 4
--- PASS: TestWorkflowsConcurrentExecution (0.16s)
PASS
ok  	github.com/projectdiscovery/nuclei/v3/pkg/core	0.271s

Checklist

  • Pull request is created against the dev branch
  • All checks passed (lint, unit/integration/regression tests etc.) with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Summary by CodeRabbit

  • Refactor
    • Parallelized execution of workflows to improve throughput on multi-step operations.
    • Enabled concurrent processing of file inputs for faster handling of large batches.
    • Reduced overall wait times and improved responsiveness during intensive tasks.
    • Preserved existing behavior and error reporting while increasing performance.

add missing `go` keyword to anonymous funcs that
were intended to run as goroutines but were
executing synchronously instead.

Fixes #6492

Signed-off-by: Dwi Siswanto <git@dw1.io>
@auto-assign auto-assign bot requested a review from Mzack9999 September 23, 2025 12:38
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 23, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Introduces concurrent execution by adding goroutines to two previously synchronous inline functions. Workflow template steps and file path processing are now launched with go func(...) { ... }(...), using existing WaitGroups for synchronization. Error handling and logging remain unchanged. No public APIs were modified.

Changes

Cohort / File(s) Summary
Workflow execution concurrency
pkg/core/workflow_execute.go
Added goroutine to execute each workflow template concurrently using existing sync.WaitGroup; preserved step execution logic and per-template error logging.
File protocol parallel processing
pkg/protocols/file/request.go
Wrapped per-file processing in a goroutine to enable parallel handling of input files; kept wg.Add()/wg.Done(), error handling, and progress tracking intact.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Runner as Executor
  participant WG as WaitGroup
  participant T1 as Template[#1]
  participant Tn as Template[#N]

  Note over Runner: Workflow execution (new)
  Runner->>WG: Add(N)
  par For each template
    Runner--)T1: go runWorkflowStep(t1,...)
    T1-->>WG: Done (defer)
  and
    Runner--)Tn: go runWorkflowStep(tn,...)
    Tn-->>WG: Done (defer)
  end
  Runner->>WG: Wait()
  WG-->>Runner: All complete
  Note over Runner: Errors logged per template
Loading
sequenceDiagram
  autonumber
  actor Caller as File Request
  participant WG as WaitGroup
  participant F1 as File[#1]
  participant Fn as File[#N]

  Note over Caller: File processing (new)
  Caller->>WG: Add(N)
  par For each file
    Caller--)F1: go processFile(f1)
    F1-->>WG: Done (defer)
  and
    Caller--)Fn: go processFile(fn)
    Fn-->>WG: Done (defer)
  end
  Caller->>WG: Wait()
  WG-->>Caller: All complete
  Note over Caller: Errors logged per file
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I thump my paws: go, go, go!
Threads now hop where once was slow.
WaitGroups watch, tick-tock in time,
Files and flows in parallel rhyme.
With swift little leaps and a whisker’s flair,
The warren hums—speed everywhere! 🐇⚡️

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues Check ✅ Passed The changes address issue #6492 by adding the missing 'go' keyword in pkg/core/workflow_execute.go and pkg/protocols/file/request.go, restoring intended goroutine-based parallelism; both closures accept their loop variables as parameters to avoid capture issues and WaitGroup usage and error handling remain consistent. These code-level modifications match the linked issue's objectives for restoring concurrency and resolving the Semgrep findings. No unrelated coding requirements from the linked issue were left unaddressed.
Out of Scope Changes Check ✅ Passed The diff is limited to adding the missing 'go' keyword in the two identified files and does not change exported signatures, introduce new dependencies, or modify unrelated logic, so there are no out-of-scope changes detected. The edits are narrowly scoped to restore intended parallel execution.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Title Check ✅ Passed The title accurately and concisely summarizes the primary change — restoring parallel processing for workflow execution and file protocol handling — which matches the PR objectives and the file-level edits that add missing goroutine invocations; it clearly highlights the main fix. It is brief and focused on the real code areas changed. The only minor clarity issues are the "[WIP]" prefix and the abbreviation "proto," but they do not misrepresent the change.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

Comment @coderabbitai help to get the list of available commands and usage tips.

@dwisiswant0 dwisiswant0 changed the title fix: restore parallel processing in workflow & file proto [WIP] fix: restore parallel processing in workflow & file proto Sep 23, 2025
@dwisiswant0 dwisiswant0 marked this pull request as draft September 23, 2025 14:42
Signed-off-by: Dwi Siswanto <git@dw1.io>
* replace hardcoded `DEBUG` env var check with
  extensible helper func.
* add support for GitHub Actions Runner env var.
* accept multiple truthy value variants.

Signed-off-by: Dwi Siswanto <git@dw1.io>
caused by shared context callbacks.

it was exposed after adding concurrent exec to
workflow processing and occurred when multiple
goroutines attempted to write to the same
`ctx.OnResult` callback field simultaneously,
causing data races during workflow template exec.

Signed-off-by: Dwi Siswanto <git@dw1.io>
Copy link
Member

@Mzack9999 Mzack9999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implementation: lgtm!

Fix: failing tests

@Mzack9999 Mzack9999 self-requested a review October 30, 2025 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Parallel processing degraded to sync execution

3 participants