mujoco_mpc
mujoco_mpc copied to clipboard
ModelDerivatives::Compute makes thread-unsafe call to mj_transitionFD
Here: https://github.com/google-deepmind/mujoco_mpc/blob/79db2bc0cc8e1ca4e96af0859718c265cdd22caf/mjpc/planners/model_derivatives.cc#L96
multiple threads are calling mjd_transitionFD on the same mjData instance. Unfortunately, mjd_transitionFD takes a non-const mjData*, and performs MuJoCo stack allocations. Those allocations are not thread safe and will get mixed up between threads, so the resulting computation is likely nonsense.
This was discovered by running tests with ThreadSanitizer.
Actually, every thread should have its own mjData, so I may have misdiagnosed the issue.