fix std::system_error in TimeoutNode #549
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a strange crash I have with the
TimeoutNode
.I'm using v4.0.1
I haven't been able to create a minimal reproducible example yet, but it happens 100% of the times in my application.
The scenario is the following:
BT::Tree
with aTimeoutNode
and an asynchronous action inside itP.S. note that I;m not using
tree->sleep()
, but this shouldn't affect the problem.This results in the following error
The "thread" mentioned in the backtrace is this https://github.com/BehaviorTree/BehaviorTree.CPP/blob/master/include/behaviortree_cpp/decorators/timer_queue.h#L71
TimeoutNode
and then destruct its member variables (among which there's theTimerQueue
).TimerQueue
destructor will add a "dummy" timer to notify the semaphore https://github.com/BehaviorTree/BehaviorTree.CPP/blob/master/include/behaviortree_cpp/decorators/timer_queue.h#L78The exception happens while trying to lock the mutex inside that lambda function.
I'm not 100% sure why we get an exception, because the order of declaration of the members in the
TimeoutNode
class should guarantee that theTimerQueue
is destroyed before the mutex.Anyhow, this PR fixes the issue for me and it seems with no side effects
Note that the error doesn't happen if I tick the tree until it succeeds (in that case it looks like the
TimeoutNode
lambda handler is called duringhaltTree
and it is not called during the destruction of theTimerQueue
.