Skip to content

Apply correct TBB shutdown mechanism - #16008

Merged
sawenzel merged 4 commits into
AliceO2Group:devfrom
jackal1-66:fixDPLHYbrid
Oct 27, 2026
Merged

sawenzel merged 4 commits into
AliceO2Group:devfrom
jackal1-66:fixDPLHYbrid

Conversation

@jackal1-66

@jackal1-66 jackal1-66 commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

This development fixes an issue in the shutdown of TBB in the Hybrid Generator, when end-of-stream is called, by overriding the stop() function and calling it in the generator destructor. The bug was found while analysing a Hyperloop wagon test on the PbPb_HGPYTHIA_536 MCGEN dataset. Since #15798 external generators are automatically expanded into a parallel GeneratorHybrid (8 sub-generators under IS_HYPERLOOP), and the job now fails with
[ERROR] Workflow crashed - PID 2161018 (generator-task) was killed abnormally with Segmentation fault and exited code was set to 139.
At the end of the test the destructor of generator hybrid is called successfully (as demonstrated by the LOG), but ~GeneratorHybrid() only sets mStopFlag = true. mTBBTaskPoolRunner is detached and never joined, so the destructor returns at once and destroys mTaskArena, mInputTaskQueue and mResultQueue while the task pool is still using them. gens was already protected by a local copy, while the arena and the queues were not. mStopFlag is moreover only polled between tasks, so a worker inside generateEvent() keeps running until that event completes.
This is why the standard MCGEN test environment triggers it: at TTL end-of-stream is raised after a few hundred events, the generator shuts down while sub-generators are mid-event.
This fix implements the stop() override that Generator implemented since #15636 . stop() raises mStopFlag and joins mTBBTaskPoolRunner, which waits for the workers to complete. GeneratorService::stopGenerators() already calls stop() at end-of-stream in dpl_eventgen. The destructor delegates to stop() as a backstop for situation that never reach it, such as a driver sending SIGTERM and the various o2-sim executables, which do not call stopGenerators().
I tested the fix with o2-sim-dpl-eventgen on the HG-Pythia parallel configuration (end-of-stream, TTL expiry and driver SIGTERM) and with o2-sim -g hybrid in parallel, sequential, cocktail and trigger modes with various num_workers, just to make sure everything is working fine.

@jackal1-66
jackal1-66 requested a review from sawenzel as a code owner October 26, 2026 12:10
Please consider the following formatting changes to AliceO2Group#16008
@jackal1-66 jackal1-66 changed the title Fix correct TBB pool closure in dpl-eventgen with TTL Apply correct TBB shutdown mechanism Oct 26, 2026

@sawenzel sawenzel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This is an important improvement and can go in after small considerations discussed in-line.

Comment thread Generators/src/GeneratorHybrid.cxx
Comment thread Generators/src/GeneratorHybrid.cxx
Comment thread Generators/src/GeneratorHybrid.cxx
Bool_t generateEvent() override;
Bool_t importParticles() override;
void updateHeader(o2::dataformats::MCEventHeader* eventHeader) override;
void stop() override; // end-of-stream hook that closes the TBB task arena

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says it closes the arena, but it only joins the TBB task pool. Could you adjust it?

Suggested change
void stop() override; // end-of-stream hook that closes the TBB task arena
void stop() override; // end-of-stream hook that joins the TBB task pool

@jackal1-66

Copy link
Copy Markdown
Collaborator Author

Ciao @sawenzel, I implemented your review. Let me know if something else is needed

@sawenzel
sawenzel merged commit 58f90b8 into AliceO2Group:dev Oct 27, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants