Skip to content

Commit

Permalink
close protocolstate shared resources in nuclei sdk/lib
Browse files Browse the repository at this point in the history
  • Loading branch information
tarunKoyalwar committed Apr 29, 2024
1 parent c9fbbe8 commit 20e0895
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/projectdiscovery/nuclei/v3/pkg/protocols"
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/hosterrorscache"
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/interactsh"
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/common/protocolstate"
"github.com/projectdiscovery/nuclei/v3/pkg/protocols/headless/engine"
"github.com/projectdiscovery/nuclei/v3/pkg/reporting"
"github.com/projectdiscovery/nuclei/v3/pkg/templates"
Expand Down Expand Up @@ -192,6 +193,8 @@ func (e *NucleiEngine) Close() {
if e.rateLimiter != nil {
e.rateLimiter.Stop()
}
// close global shared resources
protocolstate.Close()
}

// ExecuteWithCallback executes templates on targets and calls callback on each result(only if results are found)
Expand Down
5 changes: 2 additions & 3 deletions pkg/protocols/common/protocolstate/memguardian.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ var (
cancelFunc context.CancelFunc
)

func StartActiveMemGuardian() {
func StartActiveMemGuardian(ctx context.Context) {
if memguardian.DefaultMemGuardian == nil {
return
}

memTimer = time.NewTicker(memguardian.DefaultInterval)
var ctx context.Context
ctx, cancelFunc = context.WithCancel(context.Background())
ctx, cancelFunc = context.WithCancel(ctx)
go func() {
for {
select {
Expand Down
2 changes: 1 addition & 1 deletion pkg/protocols/common/protocolstate/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func Init(options *types.Options) error {
return Dialer.Dial(ctx, "tcp", addr)
})

StartActiveMemGuardian()
StartActiveMemGuardian(context.Background())

return nil
}
Expand Down

0 comments on commit 20e0895

Please sign in to comment.