ros2 runtime_error ai_generated true

Deadlock detected: callback waiting for another callback in same MutuallyExclusiveCallbackGroup

ID: ros2/rclcpp-callback-group-deadlock

Also available as: JSON · Markdown
82%Fix Rate
88%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
2 active

Root Cause

Calling a service synchronously inside a callback deadlocks the executor. The service response callback cannot run.

generic

Workarounds

  1. 92% success Use async service calls (call_async) inside callbacks
    future = client.call_async(request); rclpy.spin_until_future_complete(self, future)
  2. 90% success Use MultiThreadedExecutor with ReentrantCallbackGroup for the service client
    cb_group = ReentrantCallbackGroup(); client = self.create_client(srv_type, name, callback_group=cb_group)
  3. 82% success Move the service call to a separate thread
    import threading; threading.Thread(target=sync_service_call).start()

Dead Ends

Common approaches that don't work:

  1. Use a longer timeout on the synchronous service call 92% fail

    The call can never complete because the executor is blocked; timeout just delays the deadlock detection

  2. Create a new single-threaded executor per service call 85% fail

    Multiple executors on the same node cause undefined behavior with callbacks