You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ActionClient deadlocks if accessing goalHandle in feedback_callback #2243
) holds the mutex of the handle while calling the
feedback_callback. Therefore using any method on the handle, that tries to also acquire
the mutex will deadlock the system.
What GoalHandle are you calling with the feedback_callback, I set up a minimal ActionClient and can't seem to find how you're getting a deadlock, for instance I have:
void feedback_callback(
GoalHandle::SharedPtr, const std::shared_ptr<const ParamType::Feedback> feedback){
// Do stuff to feedback
}
Then I just have a send_goal function on a timer in a ClientConstructor, where I bind the feedback_callback. There's a mutex on every function in the file you gave in additional information. Can you explain, with code, how you're using call_feedback_callback?
I tried using the code @jmachowinski provided and none of the those three public methods, which use a std::lock_guard worked correctly. It seems that due to some sort of scoping with the executors to the client, that the data cannot even be fetched by it's own class. So anything with lock_guard may deadlock. This was still an issue even when moving from MultiThreadedExecutor to SingleThreadedExecutor which I find really odd. I don't entirely understand why the class itself can't access a function that it has ownership, especially if only one thread is trying to gain access to the data.
Since things like the return functions don't even work and we're using lock_guard to have RAII and not need to release early, it may be better to go with either std::recursive_mutex like said earlier, or now that we have access to C++17 use std::scoped_lock. Also the tests that were written a bit ago probably couldn't catch the deadlock, since they never got a false from a try_unlock or something like that.
So, what's the way forward here, should I provide a merge request that changes to recursive mutex ?
That is probably the way forward. Dropping and then reacquiring the lock can lead to its own set of problems/race conditions, so I'd rather not do that.
Activity
CursedRock17 commentedon Jul 21, 2023
What GoalHandle are you calling with the feedback_callback, I set up a minimal ActionClient and can't seem to find how you're getting a deadlock, for instance I have:
Then I just have a
send_goalfunction on a timer in a ClientConstructor, where I bind the feedback_callback. There's a mutex on every function in the file you gave in additional information. Can you explain, with code, how you're using call_feedback_callback?jmachowinski commentedon Jul 24, 2023
https://github.com/jmachowinski/rclcppActionDeadlock
This code demonstrates the issue.
There are two ways to fix this problem, either release the handle_mutex_ before calling the callback (here
rclcpp/rclcpp_action/include/rclcpp_action/client_goal_handle_impl.hpp
Line 177 in 22a954e
or make the handle_mutex a std::recursive_mutex.
tgroechel commentedon Jul 25, 2023
Would
is_feedback_awareandis_result_awarecalls also cause this? Took a quick look and I would guess they do (header APIs, impl)CursedRock17 commentedon Jul 27, 2023
I tried using the code @jmachowinski provided and none of the those three public methods, which use a
std::lock_guardworked correctly. It seems that due to some sort of scoping with the executors to the client, that the data cannot even be fetched by it's own class. So anything withlock_guardmay deadlock. This was still an issue even when moving fromMultiThreadedExecutortoSingleThreadedExecutorwhich I find really odd. I don't entirely understand why the class itself can't access a function that it has ownership, especially if only one thread is trying to gain access to the data.Since things like the return functions don't even work and we're using
lock_guardto have RAII and not need to release early, it may be better to go with eitherstd::recursive_mutexlike said earlier, or now that we have access to C++17 usestd::scoped_lock. Also the tests that were written a bit ago probably couldn't catch the deadlock, since they never got afalsefrom atry_unlockor something like that.jmachowinski commentedon Aug 4, 2023
So, what's the way forward here, should I provide a merge request that changes to recursive mutex ?
clalancette commentedon Aug 4, 2023
That is probably the way forward. Dropping and then reacquiring the lock can lead to its own set of problems/race conditions, so I'd rather not do that.