mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-17 18:05:27 +00:00
Merge pull request #6222 from fourcube/fix/slow-headless-start-and-shutdown
fix: improve headless engine startup and shutdown
This commit is contained in:
commit
160eab998c
@ -15,16 +15,15 @@ import (
|
||||
"github.com/projectdiscovery/nuclei/v3/pkg/types"
|
||||
fileutil "github.com/projectdiscovery/utils/file"
|
||||
osutils "github.com/projectdiscovery/utils/os"
|
||||
processutil "github.com/projectdiscovery/utils/process"
|
||||
)
|
||||
|
||||
// Browser is a browser structure for nuclei headless module
|
||||
type Browser struct {
|
||||
customAgent string
|
||||
tempDir string
|
||||
previousPIDs map[int32]struct{} // track already running PIDs
|
||||
engine *rod.Browser
|
||||
options *types.Options
|
||||
customAgent string
|
||||
tempDir string
|
||||
engine *rod.Browser
|
||||
options *types.Options
|
||||
launcher *launcher.Launcher
|
||||
// use getHTTPClient to get the http client
|
||||
httpClient *http.Client
|
||||
httpClientOnce *sync.Once
|
||||
@ -36,7 +35,6 @@ func New(options *types.Options) (*Browser, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not create temporary directory")
|
||||
}
|
||||
previousPIDs := processutil.FindProcesses(processutil.IsChromeProcess)
|
||||
|
||||
chromeLauncher := launcher.New().
|
||||
Leakless(false).
|
||||
@ -110,8 +108,8 @@ func New(options *types.Options) (*Browser, error) {
|
||||
engine: browser,
|
||||
options: options,
|
||||
httpClientOnce: &sync.Once{},
|
||||
launcher: chromeLauncher,
|
||||
}
|
||||
engine.previousPIDs = previousPIDs
|
||||
return engine, nil
|
||||
}
|
||||
|
||||
@ -143,6 +141,6 @@ func (b *Browser) getHTTPClient() (*http.Client, error) {
|
||||
// Close closes the browser engine
|
||||
func (b *Browser) Close() {
|
||||
b.engine.Close()
|
||||
b.launcher.Kill()
|
||||
os.RemoveAll(b.tempDir)
|
||||
processutil.CloseProcesses(processutil.IsChromeProcess, b.previousPIDs)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user