Repository navigation
Fix deadlock in model attachment - #4
Merged
Merged
Conversation
Contributor
Author
|
Hi @brta-jc gentle ping on this PR. Thanks! |
brta-jc
self-requested a review
September 29, 2026 23:53
brta-jc
approved these changes
Sep 29, 2026
brta-jc
left a comment
Collaborator
There was a problem hiding this comment.
No problem with this, thank you for the contribution. Will adopt internally as well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Fix a deadlock in the model attachment plugin when handling the
attachservice callback.Problem
The
attachCallback()function previously acquired Gazebo'sPhysicsUpdateMutex(Mutex A) before proceeding with the attachment operation.While Mutex A was held,
World::SetPaused()was subsequently called to pause the simulation, which required acquiring another internalWorldmutex (Mutex B).At the same time, Gazebo's physics update thread may acquire Mutex B during the normal physics update process and subsequently attempt to acquire Mutex A.
This results in the following lock-order inversion:
resulting in a classic AB-BA mutex deadlock.
Fix
The fix changes the order of operations so that the simulation is paused before acquiring
PhysicsUpdateMutex.The existing
PhysicsUpdateMutexprotection scope is preserved, so the attachment operation remains fully protected by the mutex. A RAII-basedPauseGuardwas introduced to manage the simulation pause state, covering the entire protected operation and restoring the world's original paused state automatically after the operation completes.This changes the ordering between the simulation pause and
PhysicsUpdateMutexacquisition without reducing the mutex's protection scope.Testing
The fix was tested in a ROS 2 Humble + Gazebo environment.
colcon build./gazebo/attachservice./gazebo/detachservice.Debugging Details
The deadlock was reproduced by directly calling the
/gazebo/attachservice.GDB confirmed a circular wait between two threads:
The attachment thread was blocked in:
The corresponding mutex information was:
The Gazebo physics update thread was blocked in the
gazebo_ros2_controljoint write path:This confirmed the circular mutex dependency described above.