open-rmf / rmf_task

RMF library for managing task allocations
Apache License 2.0
22 stars 22 forks source link

Protect phase switch from race conditions #111

Closed mxgrey closed 7 months ago

mxgrey commented 8 months ago

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.