Return result of future from spin_node_until_future_complete#107
Return result of future from spin_node_until_future_complete#107jacquelinekay merged 1 commit intomasterfrom
Conversation
|
Not so sure about changing the API to return a copy of the future result, instead of the future itself. This would fix the issue too: {
// Check the future before entering the while loop.
// If the future is already complete, don't try to spin.
std::future_status status = future.wait_for(std::chrono::seconds(0));
while (rclcpp::utilities::ok()) {
if (status == std::future_status::ready) {
return future;
}
executor.spin_node_once(node_ptr);
status = future.wait_for(std::chrono::seconds(0));
}
// Raise exception
std::runtime_error("Ctrl-C pressed or an error");
}this way we can still copy the future around, but still address the Ctrl-C signal. What do you think? We should add support for timeouts too at some point. |
|
Hmm, are there other places where we throw an exception if Can we get a third opinion on this? @wjwwood maybe? |
|
@jacquelinekay I don't think there's another place where a
via either an exception or an object that represents the status, so returning the result of the future wouldn't be feasible. |
|
Hmm, if we end up introducing timeouts then I think the status code option is the best one, so that we can differentiate between the three different completion states. |
|
I agree that a return code makes sense. |
|
Alright, I'll throw this back In Progress until I've prototyped a new return type for this function. |
|
Ok, I prototyped a "FutureReturnCode" enum, changed the function to return that type, and implemented the timeout argument. I wasn't exactly sure how to modify the parameter code for this new change; I throw exceptions in most cases where |
|
+1, it'd great to add tests for this. |
|
Jenkins looks fine: http://ci.ros2.org/job/ros2_batch_ci_linux/343/ Unless there are objections, I'm going to squash, merge, and make an issue for adding tests. |
aed40db to
2d840a5
Compare
|
+1 |
Return result of future from spin_node_until_future_complete
remove unnecessary include
Signed-off-by: Dirk Thomas <dirk-thomas@users.noreply.github.com>
…og-failed-request Add logs on failed take response/request
This is a proposed API change to make
spin_until_future_completeless prone to blocking errors.The previous behavior of the function was to block until the future was complete or if rclcpp was interrupt (i.e. by ctrl-C), and return the future object it was waiting on when complete.
This led to ros2/rmw_connext#97, where the user could not ctrl-C out of the client//service example because accessing the future object caused the thread to block. However, after a ctrl-C the future would never complete because the executor stopped executing.
Instead of returning a
shared_futureobject, the new behavior is to return a return code indicating SUCCESS, INTERRUPTED, or TIMEOUT. If SUCCESS, the future is safe to access without blocking. Also, this PR implements a timeout for the function.This PR also checks the future before calling a potentially blocking
spinfunction, to prevent indefinite blocking onrmw_waitin case a response already came in beforespin_node_until_future_completewas called.