mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 04:35:24 +00:00
Fix panic error due to file already closed in stats mode (#5774)
This commit is contained in:
parent
b57d086afc
commit
97403c203e
@ -392,6 +392,9 @@ func (r *Runner) Close() {
|
||||
if r.tmpDir != "" {
|
||||
_ = os.RemoveAll(r.tmpDir)
|
||||
}
|
||||
|
||||
//this is no-op unless nuclei is built with stats build tag
|
||||
events.Close()
|
||||
}
|
||||
|
||||
// setupPDCPUpload sets up the PDCP upload writer
|
||||
|
||||
@ -9,3 +9,6 @@ func AddScanEvent(event ScanEvent) {
|
||||
|
||||
func InitWithConfig(config *ScanConfig, statsDirectory string) {
|
||||
}
|
||||
|
||||
func Close() {
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@ type ScanStatsWorker struct {
|
||||
config *ScanConfig
|
||||
m *sync.Mutex
|
||||
directory string
|
||||
file *os.File
|
||||
enc *json.Encoder
|
||||
}
|
||||
|
||||
@ -56,7 +57,7 @@ func (s *ScanStatsWorker) initEventsFile() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
s.file = f
|
||||
s.enc = json.NewEncoder(f)
|
||||
return nil
|
||||
}
|
||||
@ -79,3 +80,22 @@ func AddScanEvent(event ScanEvent) {
|
||||
}
|
||||
defaultWorker.AddScanEvent(event)
|
||||
}
|
||||
|
||||
// Close closes the file associated with the worker
|
||||
func (s *ScanStatsWorker) Close() {
|
||||
s.m.Lock()
|
||||
defer s.m.Unlock()
|
||||
|
||||
if s.file != nil {
|
||||
_ = s.file.Close()
|
||||
s.file = nil
|
||||
}
|
||||
}
|
||||
|
||||
// Close closes the file associated with the worker
|
||||
func Close() {
|
||||
if defaultWorker == nil {
|
||||
return
|
||||
}
|
||||
defaultWorker.Close()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user