nuclei icon indicating copy to clipboard operation
nuclei copied to clipboard

[Library] Take a context for cancellation

Open gnuletik opened this issue 1 year ago • 1 comments

Please describe your feature request:

The function core.Execute should take a context.Context parameter and cancel the execution when the context is cancelled.

https://github.com/projectdiscovery/nuclei/blob/1f9a065713924b28b203e2108fc76d7a1ec49068/v2/pkg/core/executors.go#L208

The current CLI implementation bypass this limitation by calling os.Exit(1) to stop the running process:

https://github.com/projectdiscovery/nuclei/blob/1f9a065713924b28b203e2108fc76d7a1ec49068/v2/cmd/nuclei/main.go#L81-L99

The runner.Close() function is a bit misleading because it does not really close all resources:

https://github.com/projectdiscovery/nuclei/blob/1f9a065713924b28b203e2108fc76d7a1ec49068/v2/internal/runner/runner.go#L377-L378

It doesn't close / stops the running core.ChildExecuters.

Describe the use case of this feature:

This would be needed to use Nuclei as a library with timeout and cancellation.

gnuletik avatar May 10 '23 15:05 gnuletik

This will be useful. I'd like to embed nuclei as a library and be able to cancel it at any time.

stan-threatmate avatar Jan 07 '24 20:01 stan-threatmate

Fixed by https://github.com/projectdiscovery/nuclei/pull/5096

gnuletik avatar Apr 25 '24 14:04 gnuletik