JeffersonLab / JANA2

Multi-threaded HENP Event Reconstruction
https://jeffersonlab.github.io/JANA2/
Other
6 stars 9 forks source link

Event Processor Destructor Not Executing #284

Closed RaiqaRasool closed 5 months ago

RaiqaRasool commented 5 months ago

Issue Identification:

During the execution of the hd_root command with the parameters -PPLUGINS=occupancy_online, a breakpoint was added at src/programs/hd_root/MyProcessor.cc:~MyProcessor() to monitor the destructor of the event processor. However, the destructor never executed as expected. Conversely, when another breakpoint was placed at MyProcessor::Finish(), it was triggered, indicating an issue with the event processor's destructor execution.

Impact:

The absence of the destructor execution prevented the writing of data to the root file at the end of processing in hd_root. This issue hinders the expected functionality of the hd_root tool, potentially affecting data analysis and further processing.

Resolution:

To mitigate the issue, the code responsible for writing data to the root file was relocated from the destructor (~MyProcessor()) to the MyProcessor::Finish() method. This adjustment allowed the hd_root tool to populate the root files with the necessary data, resolving the immediate problem; however, the destructor is still not executing.

nathanwbrei commented 5 months ago

I think I solved this. Some additional thoughts:

  1. Closing resources should never happen in the destructor of any JANA components. That is what JEventSource::Close(), JFactory::Finish(), and JEventProcessor::Finish() are for.
  2. Components' destructors get called when the JApplication context is destroyed, not before. I believe that halld_dump allocates a JApplication and then doesn't delete it. So even though JANA is now doing the correct thing, ~MyProcessor still won't be called in your setup. Which is fine for now, because of (1).
  3. This is a memory leak, but for some reason Asan didn't detect it