Protect phase switch from race conditions #111
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.
We recently found a crash that seems to originate from the phase switching code in
rmf_task_sequence
. While it's still unclear what conditions could have caused the crash, the most likely culprit would be a race condition.This PR adds a mutex that locks before any phase switching happens, which should ensure that race conditions cannot lead to a crash happening. We also add some sanity checks that run each time a phase switch is set to happen, so if anything suspicious is going on we'll identify it before a segmentation fault can happen. Unfortunately those situations cause us to abort via exception, but that is likely a better outcome than allowing undefined behavior to proceed.