Skip to content

running nuclei with sdk may have gc problem #4836

@CyL0NG

Description

@CyL0NG

golang version: go1.21.1
platform: mac
nuclei version: v3.1.10
the following code will output:

0xc00088fd60, [0xc00ce126c0]
0xc00088fd60, [0xc00ce126c0 0xc0004598c0]
0xc00088fd60, [0xc00ce126c0 0xc0004598c0 0xc001428b40]
0xc00088fd60, [0xc00ce126c0 0xc0004598c0 0xc001428b40 0xc001428d80]
0xc00088fd60, [0xc00ce126c0 0xc0004598c0 0xc001428b40 0xc001428d80 0xc001428fc0]

the ret slice init every time in run function, it should not grow every time. When I put ret = nil at the end line in run function, it't output like this:

0xc000999900, [0xc006dbe6c0]
0xc00cafa468, [0xc004f92d80]
0xc007346540, [0xc004f92d80 0xc008b2a900]
0xc00518a040, [0xc004f92d80 0xc008b2a900 0xc008b2a6c0]
0xc00518a040, [0xc004f92d80 0xc008b2a900 0xc008b2a6c0 0xc008b2ab40]

it's like a gc problem, but use runtime.GC() is not working.

package main

import (
	"fmt"
	nuclei "github.com/projectdiscovery/nuclei/v3/lib"
	"github.com/projectdiscovery/nuclei/v3/pkg/output"
)

func run() {
	ret := make([]*output.ResultEvent, 0, 10)
	ne, err := nuclei.NewThreadSafeNucleiEngine()
	if err != nil {
		return
	}
	cb := func(event *output.ResultEvent) {
		ret = append(ret, event)
		fmt.Printf("%p, %v\n", ret, ret)
	}
	ne.GlobalResultCallback(cb)

	tf := nuclei.TemplateFilters{IDs: []string{"exposed-redis"}}
	opts := []nuclei.NucleiSDKOptions{
		nuclei.WithTemplateFilters(tf),
	}
	err = ne.ExecuteNucleiWithOpts([]string{"127.0.0.1:6379"}, opts...)
	if err != nil {
		fmt.Println("err: ", err)
	}
	ne.Close()
}

func main() {
	for i := 0; i < 5; i++ {
		run()
	}
}

Metadata

Metadata

Assignees

Labels

Type: BugInconsistencies or issues which will cause an issue or problem for users or implementors.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions