BehaviorTree.CPP icon indicating copy to clipboard operation
BehaviorTree.CPP copied to clipboard

Using ReactiveSequence/ReactiveFallback with multiple async children can cause race conditions

Open pleemann opened this issue 2 months ago • 1 comments

Describe the bug

BehaviorTree.CPP allows to implement backchaining patterns (as described e.g. in https://github.com/BehaviorTree/BehaviorTree.CPP/issues/755 ), but there is a challenge with the current implementation: As described in https://github.com/BehaviorTree/BehaviorTree.CPP/issues/83#issuecomment-479520971, which also provides a good minimal example, a previously RUNNING child is halted only after another child is started (its onStart is executed). So for a short amount of time, there are two children in RUNNING state.

In a scenario, where the async children start ROS actions in the onStart function, and cancel the actions in the onHalted, this can lead to race conditions in the system, as multiple actions are running simultaneously.

There was a PR to address this problem, https://github.com/BehaviorTree/BehaviorTree.CPP/pull/93, but sadly, it was never merged. Is there a better solution to address this problem? If the solution proposed in that PR is still the way to go, I can also spend some time to update it to the most recent version of the library (as the PR is quite old).

pleemann avatar Oct 27 '25 10:10 pleemann

you or anyone else is welcome to work on creating a new PR or to rebase and simplify #93

facontidavide avatar Oct 30 '25 05:10 facontidavide