Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing most go routine leaks #3073

Merged
merged 2 commits into from
Dec 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion v2/cmd/integration-test/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ func executeNucleiAsCode(templatePath, templateURL string) ([]string, error) {

home, _ := os.UserHomeDir()
catalog := disk.NewCatalog(path.Join(home, "nuclei-templates"))
ratelimiter := ratelimit.New(context.Background(), 150, time.Second)
defer ratelimiter.Stop()
executerOpts := protocols.ExecuterOptions{
Output: outputWriter,
Options: defaultOpts,
Progress: mockProgress,
Catalog: catalog,
IssuesClient: reportingClient,
RateLimiter: ratelimit.New(context.Background(), 150, time.Second),
RateLimiter: ratelimiter,
Interactsh: interactClient,
HostErrorsCache: cache,
Colorizer: aurora.NewAurora(true),
Expand Down
1 change: 1 addition & 0 deletions v2/cmd/nuclei/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func main() {
// Setup graceful exits
resumeFileName := types.DefaultResumeFilePath()
c := make(chan os.Signal, 1)
defer close(c)
signal.Notify(c, os.Interrupt)
go func() {
for range c {
Expand Down
2 changes: 1 addition & 1 deletion v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ require (
github.com/projectdiscovery/fasttemplate v0.0.2
github.com/projectdiscovery/goflags v0.1.6
github.com/projectdiscovery/nvd v1.0.9
github.com/projectdiscovery/ratelimit v0.0.3
github.com/projectdiscovery/ratelimit v0.0.4-0.20221222024635-17151503fe59
github.com/projectdiscovery/rdap v0.9.1-0.20221108103045-9865884d1917
github.com/projectdiscovery/sarif v0.0.1
github.com/projectdiscovery/tlsx v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,8 @@ github.com/projectdiscovery/networkpolicy v0.0.3 h1:OZFPkMVY6SJxc1ncuRXB2VlT6xlz
github.com/projectdiscovery/networkpolicy v0.0.3/go.mod h1:DIXwKs3sQyfCoWHKRLQiRrEorSQW4Zrh4ftu7oDVK6w=
github.com/projectdiscovery/nvd v1.0.9 h1:2DdMm7lu3GnCQsyYDEQiQ/LRYDmpEm654kvGQS6jzjE=
github.com/projectdiscovery/nvd v1.0.9/go.mod h1:nGHAo7o6G4V4kscZlm488qKp/ZrZYiBoKqAQrn3X4Og=
github.com/projectdiscovery/ratelimit v0.0.3 h1:6c8QKL3ivOdjXqbP+UA2jsTNHcH0OMHk+4AMkanOkUo=
github.com/projectdiscovery/ratelimit v0.0.3/go.mod h1:WBz8N1P+CyxnfUoGfVCqah4NZ2SreSX7v9dY8wIlK70=
github.com/projectdiscovery/ratelimit v0.0.4-0.20221222024635-17151503fe59 h1:XHi//FUJTo+RRKfLT9Mj6oqkQq9E65uNMhL2RVuG5zA=
github.com/projectdiscovery/ratelimit v0.0.4-0.20221222024635-17151503fe59/go.mod h1:WBz8N1P+CyxnfUoGfVCqah4NZ2SreSX7v9dY8wIlK70=
github.com/projectdiscovery/rawhttp v0.1.4 h1:zdOqU1DUY2dGoyCzBqzHnHVwPyv32j+Hke8KfLRUouI=
github.com/projectdiscovery/rawhttp v0.1.4/go.mod h1:mhSXo96awUUr20VdReDYUKxldsvR5841FRgiaoaxDCY=
github.com/projectdiscovery/rdap v0.9.1-0.20221108103045-9865884d1917 h1:m03X4gBVSorSzvmm0bFa7gDV4QNSOWPL/fgZ4kTXBxk=
Expand Down
3 changes: 3 additions & 0 deletions v2/internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ func (r *Runner) Close() {
if r.pprofServer != nil {
_ = r.pprofServer.Shutdown(context.Background())
}
if r.ratelimiter != nil {
r.ratelimiter.Stop()
}
}

// RunEnumeration sets up the input layer for giving input nuclei.
Expand Down
12 changes: 12 additions & 0 deletions v2/pkg/protocols/common/interactsh/interactsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,18 @@ func (c *Client) Close() bool {
c.interactsh.StopPolling()
c.interactsh.Close()
}

closeCache := func(cc *ccache.Cache) {
if cc != nil {
cc.Clear()
cc.Stop()
}
}
closeCache(c.requests)
closeCache(c.interactions)
closeCache(c.matchedTemplates)
closeCache(c.interactshURLs)

return c.matched
}

Expand Down
3 changes: 3 additions & 0 deletions v2/pkg/protocols/common/uncover/uncover.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func getTargets(uncoverOptions *ucRunner.Options, field string) (chan string, er
} else {
rateLimiter = ratelimit.NewUnlimited(context.Background())
}
if rateLimiter != nil {
defer rateLimiter.Stop()
}
var agents []uncover.Agent
// declare clients
for _, engine := range uncoverOptions.Engine {
Expand Down