removing most go routine leaks (#3073)

Co-authored-by: sandeep <8293321+ehsandeep@users.noreply.github.com>
dev
Mzack9999 2022-12-24 14:52:14 +01:00 committed by GitHub
parent aee0870617
commit 34976029d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 25 additions and 4 deletions

View File

@ -93,13 +93,15 @@ func executeNucleiAsCode(templatePath, templateURL string) ([]string, error) {
home, _ := os.UserHomeDir() home, _ := os.UserHomeDir()
catalog := disk.NewCatalog(path.Join(home, "nuclei-templates")) catalog := disk.NewCatalog(path.Join(home, "nuclei-templates"))
ratelimiter := ratelimit.New(context.Background(), 150, time.Second)
defer ratelimiter.Stop()
executerOpts := protocols.ExecuterOptions{ executerOpts := protocols.ExecuterOptions{
Output: outputWriter, Output: outputWriter,
Options: defaultOpts, Options: defaultOpts,
Progress: mockProgress, Progress: mockProgress,
Catalog: catalog, Catalog: catalog,
IssuesClient: reportingClient, IssuesClient: reportingClient,
RateLimiter: ratelimit.New(context.Background(), 150, time.Second), RateLimiter: ratelimiter,
Interactsh: interactClient, Interactsh: interactClient,
HostErrorsCache: cache, HostErrorsCache: cache,
Colorizer: aurora.NewAurora(true), Colorizer: aurora.NewAurora(true),

View File

@ -82,6 +82,7 @@ func main() {
// Setup graceful exits // Setup graceful exits
resumeFileName := types.DefaultResumeFilePath() resumeFileName := types.DefaultResumeFilePath()
c := make(chan os.Signal, 1) c := make(chan os.Signal, 1)
defer close(c)
signal.Notify(c, os.Interrupt) signal.Notify(c, os.Interrupt)
go func() { go func() {
for range c { for range c {

View File

@ -74,7 +74,7 @@ require (
github.com/projectdiscovery/fasttemplate v0.0.2 github.com/projectdiscovery/fasttemplate v0.0.2
github.com/projectdiscovery/goflags v0.1.6 github.com/projectdiscovery/goflags v0.1.6
github.com/projectdiscovery/nvd v1.0.9 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/rdap v0.9.1-0.20221108103045-9865884d1917
github.com/projectdiscovery/sarif v0.0.1 github.com/projectdiscovery/sarif v0.0.1
github.com/projectdiscovery/tlsx v1.0.0 github.com/projectdiscovery/tlsx v1.0.0

View File

@ -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/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 h1:2DdMm7lu3GnCQsyYDEQiQ/LRYDmpEm654kvGQS6jzjE=
github.com/projectdiscovery/nvd v1.0.9/go.mod h1:nGHAo7o6G4V4kscZlm488qKp/ZrZYiBoKqAQrn3X4Og= 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.4-0.20221222024635-17151503fe59 h1:XHi//FUJTo+RRKfLT9Mj6oqkQq9E65uNMhL2RVuG5zA=
github.com/projectdiscovery/ratelimit v0.0.3/go.mod h1:WBz8N1P+CyxnfUoGfVCqah4NZ2SreSX7v9dY8wIlK70= 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 h1:zdOqU1DUY2dGoyCzBqzHnHVwPyv32j+Hke8KfLRUouI=
github.com/projectdiscovery/rawhttp v0.1.4/go.mod h1:mhSXo96awUUr20VdReDYUKxldsvR5841FRgiaoaxDCY= github.com/projectdiscovery/rawhttp v0.1.4/go.mod h1:mhSXo96awUUr20VdReDYUKxldsvR5841FRgiaoaxDCY=
github.com/projectdiscovery/rdap v0.9.1-0.20221108103045-9865884d1917 h1:m03X4gBVSorSzvmm0bFa7gDV4QNSOWPL/fgZ4kTXBxk= github.com/projectdiscovery/rdap v0.9.1-0.20221108103045-9865884d1917 h1:m03X4gBVSorSzvmm0bFa7gDV4QNSOWPL/fgZ4kTXBxk=

View File

@ -332,6 +332,9 @@ func (r *Runner) Close() {
if r.pprofServer != nil { if r.pprofServer != nil {
_ = r.pprofServer.Shutdown(context.Background()) _ = r.pprofServer.Shutdown(context.Background())
} }
if r.ratelimiter != nil {
r.ratelimiter.Stop()
}
} }
// RunEnumeration sets up the input layer for giving input nuclei. // RunEnumeration sets up the input layer for giving input nuclei.

View File

@ -261,6 +261,18 @@ func (c *Client) Close() bool {
c.interactsh.StopPolling() c.interactsh.StopPolling()
c.interactsh.Close() 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 return c.matched
} }

View File

@ -107,6 +107,9 @@ func getTargets(uncoverOptions *ucRunner.Options, field string) (chan string, er
} else { } else {
rateLimiter = ratelimit.NewUnlimited(context.Background()) rateLimiter = ratelimit.NewUnlimited(context.Background())
} }
if rateLimiter != nil {
defer rateLimiter.Stop()
}
var agents []uncover.Agent var agents []uncover.Agent
// declare clients // declare clients
for _, engine := range uncoverOptions.Engine { for _, engine := range uncoverOptions.Engine {