mujoco_mpc icon indicating copy to clipboard operation
mujoco_mpc copied to clipboard

ModelDerivatives::Compute makes thread-unsafe call to mj_transitionFD

Open nimrod-gileadi opened this issue 1 year ago • 1 comments

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.

nimrod-gileadi avatar Jul 31 '24 17:07 nimrod-gileadi

Actually, every thread should have its own mjData, so I may have misdiagnosed the issue.

nimrod-gileadi avatar Jul 31 '24 17:07 nimrod-gileadi