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 Crash: Taking data from action client but nothing is ready #2242
after some time we get the exception terminate called after throwing an instance of 'std::runtime_error' what(): Taking data from action client but nothing is ready
Additional information
Using a multi threaded spinner, but the default callback group, I guess this one is mutual exclusive
Could you prepare a minimal example that one could build and run to reproduce the error? It would also provide clarity on how various callbacks are defined.
I tried to create a minimal example, and figured out, that the cause of this issue was most likely due to deadlock issues in the client or the server. I can not reproduce the issue as original described in the minimal example.
However I managed reproduce the error now with a slightly different setup.
start server
start the client
strg+c the client
directly restart the client
Server:
terminate called after throwing an instance of 'rclcpp::exceptions::RCLError'
what(): goal_handle attempted invalid transition from state EXECUTING with event CANCELED, at ./src/rcl_action/goal_handle.c:95
Aborted (core dumped)
client:
terminate called after throwing an instance of 'std::runtime_error'
what(): Taking data from action client but nothing is ready
Aborted (core dumped)
start the client
start the server
client just runs
server directly crashes with
./server
terminate called after throwing an instance of 'std::runtime_error'
what(): Taking data from action server but nothing is ready
Aborted (core dumped)
Note, you need to do this multiple times, about 1 time out of 10 the error will trigger.
Okay, I had a look at the code now and it it pretty obvious that a race condition is ongoing.
In order to fix this, I would need some background information on
rcl_action_server_wait_set_get_entities_ready
or repectitive
rcl_wait
From the documentation of this function, it is unclear to me if it may return multiple events to be ready at once. @wjwwood You seem to have worked a lot on this code, do you know the answer ?
I dug further into this issue, and from my tests I can see, that rcl_action_server_wait_set_get_entities_ready may return multiple events at one time.
Now I am a bit more lost on how to correctly map this to the waitable interface, as is_ready can not signal that multiple events are ready. The only way I see currently is to keep track of incoming events, as reported events through the waitable interface, which is somewhat cumbersome. Any ideas ?
I can reproduce the following exception on server side.
terminate called after throwing an instance of 'rclcpp::exceptions::RCLError'what(): goal_handle attempted invalid transition from state EXECUTING with event CANCELED, at ./src/rcl_action/goal_handle.c:95
Aborted (core dumped)
i think what expected here is, user callback should decide if accepted or not only, then process canceling sequence in the application then call canceled on that goal_handler.
btw, the following patch is required to build with rolling.
I think goal_handle attempted invalid transition can be resolved with application code, and doc fix #2266.
This fixes the 'Taking data from client' issues for us.
on this one, i cannot reproduce this one, can you elaborate what the root case of this before starting review? that would be really appreciated to understand the problem 1st.
rcl_ret_t ret = rcl_action_client_wait_set_get_entities_ready(
wait_set, pimpl_->client_handle.get(),
&pimpl_->is_feedback_ready,
&pimpl_->is_status_ready,
&pimpl_->is_goal_response_ready,
&pimpl_->is_cancel_response_ready,
&pimpl_->is_result_response_ready);
This function will be called by get_next_executable deep under the hood.
The important point here is that the kind of next executable is stored in the global pimpl.
This function is called by execute_any_executable. As pointed out above, this call is not protected any more by a lock, and
any other thread may have been calling ClientBase::is_ready in-between.
As one can see, the execute function uses the values in the global pimpl object to determine the kind of action that needs processing. This it the point were the race occurs, as the global pimpl may have been altered by another thread, leading to the "Executing action client but nothing is ready" exception.
if (pimpl_->is_feedback_ready) {
} elseif (pimpl_->is_status_ready) {
} elseif (pimpl_->is_goal_response_ready) {
} elseif (pimpl_->is_result_response_ready) {
} elseif (pimpl_->is_cancel_response_ready) {
} else {
throwstd::runtime_error("Executing action client but nothing is ready");
}
Note, I also saw races between is_ready and take_data. Which are a mystery to me, as this should be protected by the mutex in the spinner. The patch also addresses these.
Hi @jmachowinski , thank you for your digging and elaboration on the issue. We have been encountering it in our project since april, randomly in some 1/10 cases and seemingly dependent on the computer utilization. I am now testing our application with your fix and will let you know once I will be able to determine if it helps.
I hope this issue gets more attention here, dear ROS2 guys, it would really help to speed up the review of the related PR:)
@jmachowinski we ran into the same issue and it's kind of a blocker for us due to its quite consistent reproduction. Your explanation here was very useful to bootstrap the investigation we have started as well however there is one thing we cannot puzzle - originally you talked about runtime exception with a message "Taking data from action client but nothing is ready" (and we get exactly the same error) but your explanation leads to "Executing action client but nothing is ready" which seems to be different (at least we haven't seen that one yet). Does it mean that ones you fixed the race between is_ready() and take_data() you started to see execute() call throwing that runtime exception?
@medvedevigorek Its a race between the tree function. is_ready() sets class members, which represent which data must be taken. In take_data() theses members are actually not cleared, as they are 'misused' to store the type of data that was taken. Later in execute the class members are used to figure out what kind of data was taken, and the class members are cleared. This leads to the three possible failures:
is_ready might be called in between take_data and execute, which leads to a wrong cast of the taken data -> segfault
is_ready signals data to be taken, execute intterupts and clears the member, take_data finds no member set and throws "Taking data from action client but nothing is ready" .
is_ready is called, and a message is ready, take data is called, thread change before execute is called. Second thread jumps in, calls is_ready, and a second message is ready, take data is called. Execute is called (still in the second thread), the class member for the message is cleared. Thread 1 calls execute, and does not find any set class member and throws "Executing action client but nothing is ready"
@jmachowinski, I was thinking about clearing waitable_triggered_handles_ along with other handles in clear_handles() as it's called by the executor in the beginning of wait_for_work() routine. However I am not sure about the contract here as potentially the following is possible: collect_entities() adds a waitable in the list, it's then moved to waitable_triggered_handles_ but not getting executed, on the next iteration the same waitable is not added into the list as it's not in a group anymore hence it's not executed while it was marked ready for execution on the previous iteration. I am not that familiar with the internals so cannot say for sure if such scenario is even a valid one or not. Something tells it's not but didn't want to have more issues so went with a check before adding a waitable instead of clearing the list. If someone familiar with the matter can confirm that then clearing the triggered list might be a better approach.
on the next iteration the same waitable is not added into the list as it's not in a group anymore
@medvedevigorek when you say this, do you mean it's not in a group (I assumed you mean callback group) anymore because it was deleted? Or for some other reason?
@wjwwood yes, I meant callback group. collect_entities collects waitables from callback groups and later a waitable can be moved to waitable_triggered_handles list. And the question was if collect_entities is called again is it possible to not have the same waitable collected again? If it's not possible then clearing the waitable_triggered_handles might be okay.
@jmachowinski Could you eleborate how? I am willing to put in the effort into backporting this patch to iron as it basically makes it impossible to run any ros2control application for a longer period when using any controller with an action interface.
@jmachowinski Could you eleborate how? I am willing to put in the effort into backporting this patch to iron as it basically makes it impossible to run any ros2control application for a longer period when using any controller with an action interface.
Use the patch from #2495 and change it, so that the signature of
Activity
Yadunund commentedon Jul 21, 2023
Could you prepare a minimal example that one could build and run to reproduce the error? It would also provide clarity on how various callbacks are defined.
jmachowinski commentedon Jul 24, 2023
I tried to create a minimal example, and figured out, that the cause of this issue was most likely due to deadlock issues in the client or the server. I can not reproduce the issue as original described in the minimal example.
However I managed reproduce the error now with a slightly different setup.
https://github.com/jmachowinski/rclcppActionDeadlock branch nothingReady
start server
start the client
strg+c the client
directly restart the client
Server:
client:
start the client
start the server
client just runs
server directly crashes with
Note, you need to do this multiple times, about 1 time out of 10 the error will trigger.
jmachowinski commentedon Jul 28, 2023
Okay, I had a look at the code now and it it pretty obvious that a race condition is ongoing.
In order to fix this, I would need some background information on
or repectitive
From the documentation of this function, it is unclear to me if it may return multiple events to be ready at once.
@wjwwood You seem to have worked a lot on this code, do you know the answer ?
jmachowinski commentedon Aug 1, 2023
I dug further into this issue, and from my tests I can see, that rcl_action_server_wait_set_get_entities_ready may return multiple events at one time.
Now I am a bit more lost on how to correctly map this to the waitable interface, as is_ready can not signal that multiple events are ready. The only way I see currently is to keep track of incoming events, as reported events through the waitable interface, which is somewhat cumbersome. Any ideas ?
fujitatomoya commentedon Aug 4, 2023
I can reproduce the following exception on server side.
i believe this is because
canceledis called ongoal_handlerin thehandle_cancel_user callback. (cancel request is not accepted yet, that saying the goal is NOT canceling state yet.) after all,rcl_actiondetects this as invalid transition as designed, https://design.ros2.org/articles/actions.html.i think what expected here is, user callback should decide if accepted or not only, then process canceling sequence in the application then call
canceledon thatgoal_handler.btw, the following patch is required to build with
rolling.gdb core stacktrace
fujitatomoya commentedon Aug 4, 2023
@jmachowinski i think doc section is not correct, see #2266
jmachowinski commentedon Aug 21, 2023
@fujitatomoya I agree.
Can someone review #2250 ?
This fixes the 'Taking data from client' issues for us.
fujitatomoya commentedon Aug 21, 2023
I think
goal_handle attempted invalid transitioncan be resolved with application code, and doc fix #2266.on this one, i cannot reproduce this one, can you elaborate what the root case of this before starting review? that would be really appreciated to understand the problem 1st.
jmachowinski commentedon Aug 22, 2023
This problem is hard to reproduce, you need a certain workload and a actions running with a multithreaded spinner.
As for the explanation of what is going on, this is a long one...
First we need to look at the multithreaded executor:
rclcpp/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp
Lines 82 to 100 in e296583
The important point here is that get_next_executable is called with a lock and execute_any_executable(any_exec) is called without the lock.
Now we need to look at the function
rclcpp/rclcpp_action/src/client.cpp
Lines 266 to 274 in e296583
This function will be called by get_next_executable deep under the hood.
The important point here is that the kind of next executable is stored in the global pimpl.
Next is the function
rclcpp/rclcpp_action/src/client.cpp
Line 622 in e296583
This function is called by execute_any_executable. As pointed out above, this call is not protected any more by a lock, and
any other thread may have been calling ClientBase::is_ready in-between.
As one can see, the execute function uses the values in the global pimpl object to determine the kind of action that needs processing. This it the point were the race occurs, as the global pimpl may have been altered by another thread, leading to the "Executing action client but nothing is ready" exception.
Note, I also saw races between is_ready and take_data. Which are a mystery to me, as this should be protected by the mutex in the spinner. The patch also addresses these.
jmachowinski commentedon Aug 24, 2023
@fujitatomoya is the issue now clear to you ?
doisyg commentedon Sep 3, 2023
Seeing a simialr error on a code that was running fine under
humblejmachowinski commentedon Sep 4, 2023
@doisyg does MR #2250 fix the issue for you ?
tommy-erko commentedon Oct 10, 2023
Hi @jmachowinski , thank you for your digging and elaboration on the issue. We have been encountering it in our project since april, randomly in some 1/10 cases and seemingly dependent on the computer utilization. I am now testing our application with your fix and will let you know once I will be able to determine if it helps.
I hope this issue gets more attention here, dear ROS2 guys, it would really help to speed up the review of the related PR:)
medvedevigorek commentedon Nov 7, 2023
@jmachowinski we ran into the same issue and it's kind of a blocker for us due to its quite consistent reproduction. Your explanation here was very useful to bootstrap the investigation we have started as well however there is one thing we cannot puzzle - originally you talked about runtime exception with a message "Taking data from action client but nothing is ready" (and we get exactly the same error) but your explanation leads to "Executing action client but nothing is ready" which seems to be different (at least we haven't seen that one yet). Does it mean that ones you fixed the race between
is_ready()andtake_data()you started to seeexecute()call throwing that runtime exception?jmachowinski commentedon Nov 7, 2023
@medvedevigorek Its a race between the tree function. is_ready() sets class members, which represent which data must be taken. In take_data() theses members are actually not cleared, as they are 'misused' to store the type of data that was taken. Later in execute the class members are used to figure out what kind of data was taken, and the class members are cleared. This leads to the three possible failures:
Note that #2250 is a working fix
2 remaining items
medvedevigorek commentedon Nov 13, 2023
@jmachowinski, I was thinking about clearing
waitable_triggered_handles_along with other handles inclear_handles()as it's called by the executor in the beginning ofwait_for_work()routine. However I am not sure about the contract here as potentially the following is possible:collect_entities()adds a waitable in the list, it's then moved towaitable_triggered_handles_but not getting executed, on the next iteration the same waitable is not added into the list as it's not in a group anymore hence it's not executed while it was marked ready for execution on the previous iteration. I am not that familiar with the internals so cannot say for sure if such scenario is even a valid one or not. Something tells it's not but didn't want to have more issues so went with a check before adding a waitable instead of clearing the list. If someone familiar with the matter can confirm that then clearing the triggered list might be a better approach.wjwwood commentedon Nov 21, 2023
@medvedevigorek when you say this, do you mean it's not in a group (I assumed you mean callback group) anymore because it was deleted? Or for some other reason?
jmachowinski commentedon Nov 21, 2023
@wjwwood Its not added by
collect_entities(), as the waitable is at this point of time in execution, and therefore filtered out of the waitset.See
rclcpp/rclcpp/include/rclcpp/strategies/allocator_memory_strategy.hpp
Line 162 in d08d9cf
medvedevigorek commentedon Nov 25, 2023
@wjwwood yes, I meant callback group.
collect_entitiescollects waitables from callback groups and later a waitable can be moved towaitable_triggered_handleslist. And the question was ifcollect_entitiesis called again is it possible to not have the same waitable collected again? If it's not possible then clearing thewaitable_triggered_handlesmight be okay.jmachowinski commentedon Apr 10, 2024
Fixed by the merge of #2495 in jazzy
alexmillane commentedon Apr 23, 2024
Thank you for your efforts in fixing this. Is there a possibility to backport it to humble? 🙏
fujitatomoya commentedon Apr 23, 2024
@alexmillane unfortunately i do not think we can do that, since #2495 is API/ABI break change.
jmachowinski commentedon Apr 23, 2024
Its pretty much straight forward to modify the patch to be non ABI/API breaking. @alexmillane feel free to do it ;-)
dsandber commentedon May 7, 2024
Looking at #2250 it seems this was applied to rolling/jazzy. Has anyone tried to apply to iron? Does the patch apply cleanly? Thanks!
PS. Or can the (patched) rolling rclcpp package be used with an iron distro?
firesurfer commentedon May 13, 2024
@jmachowinski Could you eleborate how? I am willing to put in the effort into backporting this patch to iron as it basically makes it impossible to run any ros2control application for a longer period when using any controller with an action interface.
jmachowinski commentedon May 13, 2024
Use the patch from #2495 and change it, so that the signature of
and the enum
are not changed. Should be straight forward.
edgarcamilocamacho commentedon Sep 30, 2024
Hello @alexmillane and @doisyg, I just backported the fix from
ironbranch tohumbleand created the PR #2635fix(bringup): drop the multi-threaded executor from f1tenth_container
docs: bug-257 root cause and fix, movement_time_allowance verified pa…