[BUG] ExecuteCallbackWithCtx leaves dangling goroutines when context is canceled #5989
Open
1 task done
Labels
Type: Bug
Inconsistencies or issues which will cause an issue or problem for users or implementors.
Is there an existing issue for this?
Current Behavior
The ExecuteCallbackWithCtx function in the sdk does not seem to clean up properly when the context is canceled and leaves running goroutines behind. These goroutines will cause a panic (nil pointer dereference) if the engine is closed right after, which should be safe to do as nothing should be running at that point.
I investigated a little bit to see if I could find the source of these dangling goroutines, still not sure if this is the cause but I saw that both host spray and template spray strategies are not deferring the workpool Wait call, so it does not get called when the context is canceled and the function returns:
For host sprays:
nuclei/pkg/core/executors.go
Lines 159 to 172 in e4a0b8e
For template sprays:
nuclei/pkg/core/execute_options.go
Lines 104 to 116 in e4a0b8e
Both of these functions call Wait at the end, but if the context is canceled, the functions will return early and not wait for workers to finish. Maybe the Wait() call should be deferred as below?
I believe it could be either this or some inner goroutine leak that does not take the context into consideration.
I can dig deeper and try to come up with a fix if you think the issue is valid.
Expected Behavior
ExecuteCallbackWithCtx should not return until all goroutines have finished. If the context is canceled, context cancellation should be propagated to all running goroutines and properly handled.
Steps To Reproduce
The following code should help reproducing the issue:
Relevant log output
Environment
Anything else?
No response
The text was updated successfully, but these errors were encountered: