Skip to content

[RF] Don't touch deleted nodes in RooFit::Evaluator destructor - #23893

Merged
guitargeek merged 1 commit into
root-project:masterfrom
guitargeek:fix-evaluator-dangling-nodes
Oct 30, 2026
Merged

guitargeek merged 1 commit into
root-project:masterfrom
guitargeek:fix-evaluator-dangling-nodes

Conversation

@guitargeek

@guitargeek guitargeek commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

The Evaluator resets the data tokens of all nodes of its computation graph in the destructor, through raw pointers and without knowing whether the nodes still exist. Nodes that outlive the Evaluator need this reset, because a node can only be registered with one Evaluator at a time. But nodes can also be deleted before the Evaluator: the compiled NLL graph of a RooMomentMorphFuncND references the original morph function and its RooHistPdf templates owned by the RooWorkspace, and at the exit of a Python script the garbage collector can delete the workspace before the NLL object. The destructor then writes into freed memory, which showed up as a free(): invalid pointer abort of tutorial-roofit-roofit-rf616_morphing-py in the v6-42-00-rc1 release build on ubuntu2610 (valgrind: "Invalid write of size 8" in RooFit::Evaluator::~Evaluator()).

Track the ownership of the data token: RooAbsArg remembers the Evaluator that set its token, tells it in the destructor that the node is gone (Evaluator::unregisterNode), and the Evaluator skips such nodes when resetting the tokens.

Add a unit test for the Evaluator that deletes a node before the Evaluator and checks that tokens can be reused in both orders, and a regression test for the workspace-deleted-before-NLL scenario with the morph pdf.

This also means we can remove the workarounds in the tutorials introduced by commits 49fb353 and 0687911.

Fixes #23904

🤖 Done with the help of AI

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Test Results

    24 files      24 suites   3d 20h 46m 46s ⏱️
 3 906 tests  3 906 ✅ 0 💤 0 ❌
83 670 runs  83 670 ✅ 0 💤 0 ❌

Results for commit ff4cb8a.

♻️ This comment has been updated with latest results.

The Evaluator resets the data tokens of all nodes of its computation
graph in the destructor, through raw pointers and without knowing
whether the nodes still exist. Nodes that outlive the Evaluator need
this reset, because a node can only be registered with one Evaluator at
a time. But nodes can also be deleted before the Evaluator: the compiled
NLL graph of a RooMomentMorphFuncND references the original morph
function and its RooHistPdf templates owned by the RooWorkspace, and at
the exit of a Python script the garbage collector can delete the
workspace before the NLL object. The destructor then writes into freed
memory, which showed up as a `free(): invalid pointer` abort of
tutorial-roofit-roofit-rf616_morphing-py in the v6-42-00-rc1 release
build on ubuntu2610 (valgrind: "Invalid write of size 8" in
RooFit::Evaluator::~Evaluator()).

Track the ownership of the data token: RooAbsArg remembers the Evaluator
that set its token, tells it in the destructor that the node is gone
(Evaluator::unregisterNode), and the Evaluator skips such nodes when
resetting the tokens.

Add a unit test for the Evaluator that deletes a node before the
Evaluator and checks that tokens can be reused in both orders, and a
regression test for the workspace-deleted-before-NLL scenario with the
morph pdf.

This also means we can remove the workarounds in the tutorials
introduced by commits 49fb353 and 0687911.

🤖 Done with the help of AI
@guitargeek
guitargeek force-pushed the fix-evaluator-dangling-nodes branch from e66e7c5 to ff4cb8a Compare October 29, 2026 21:10
@dpiparo

dpiparo commented Oct 30, 2026

Copy link
Copy Markdown
Member

To be backported to 6.42 and 6.40 perhaps?

@guitargeek

Copy link
Copy Markdown
Contributor Author

Yes I'll do that! Thanks for the review

@guitargeek
guitargeek merged commit 8242cdc into root-project:master Oct 30, 2026
35 of 36 checks passed
@guitargeek

Copy link
Copy Markdown
Contributor Author

/backport to 6.42, 6.40

@guitargeek
guitargeek deleted the fix-evaluator-dangling-nodes branch October 30, 2026 08:02
@root-project-bot

Copy link
Copy Markdown

Preparing to backport PR #23893 to branches 6.42 and 6.40 requested by guitargeek

@root-project-bot

Copy link
Copy Markdown

Something went wrong with the creation of the PR to backport to 6.40: @guitargeek please see the logs

@root-project-bot

Copy link
Copy Markdown

This PR has been backported to branch 6.42: #23905

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RF] Deleted nodes are manipulated in RooFit::Evaluator destructor

3 participants