Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure rmw_destroy_node() completes despite run-time errors. #458

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions rmw_fastrtps_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,34 @@ rmw_destroy_node(rmw_node_t * node)
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);

rmw_context_t * context = node->context;
rmw_ret_t ret = rmw_fastrtps_shared_cpp::__rmw_destroy_node(

rmw_ret_t ret = RMW_RET_OK;
rmw_error_state_t error_state;
rmw_ret_t inner_ret = rmw_fastrtps_shared_cpp::__rmw_destroy_node(
eprosima_fastrtps_identifier, node);
if (RMW_RET_OK != ret) {
return ret;
error_state = *rmw_get_error_state();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't want to log the error here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There're no errors before this one, so we can put in the local error state w/o printing.

ret = inner_ret;
rmw_reset_error();
}

inner_ret = rmw_fastrtps_shared_cpp::decrement_context_impl_ref_count(context);
if (RMW_RET_OK != inner_ret) {
if (RMW_RET_OK != ret) {
RMW_SAFE_FWRITE_TO_STDERR(rmw_get_error_string().str);
RMW_SAFE_FWRITE_TO_STDERR(" during '" RCUTILS_STRINGIFY(__function__) "'\n");
} else {
error_state = *rmw_get_error_state();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an easy way to combine the two error states should there be multiple failures?

Copy link
Contributor Author

@hidmic hidmic Oct 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of today, there isn't. In general, we don't handle errors during error handling and/or finalization very well or at all. I opened an issue about this: ros2/rcutils#269, to have an standard idiom for it.

For the moment, this makes sure the first error goes into the error state and any other errors that may follow do not get lost but do not obscure what is assumed to be the root cause of the error.

ret = inner_ret;
}
rmw_reset_error();
}

if (RMW_RET_OK != ret) {
rmw_set_error_state(error_state.message, error_state.file, error_state.line_number);
}
return rmw_fastrtps_shared_cpp::decrement_context_impl_ref_count(context);

return ret;
}

const rmw_guard_condition_t *
Expand Down
28 changes: 25 additions & 3 deletions rmw_fastrtps_dynamic_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,34 @@ rmw_destroy_node(rmw_node_t * node)
eprosima_fastrtps_identifier,
return RMW_RET_INCORRECT_RMW_IMPLEMENTATION);
rmw_context_t * context = node->context;
rmw_ret_t ret = rmw_fastrtps_shared_cpp::__rmw_destroy_node(

rmw_ret_t ret = RMW_RET_OK;
rmw_error_state_t error_state;
rmw_ret_t inner_ret = rmw_fastrtps_shared_cpp::__rmw_destroy_node(
eprosima_fastrtps_identifier, node);
if (RMW_RET_OK != ret) {
return ret;
error_state = *rmw_get_error_state();
ret = inner_ret;
rmw_reset_error();
}

inner_ret = rmw_fastrtps_shared_cpp::decrement_context_impl_ref_count(context);
if (RMW_RET_OK != inner_ret) {
if (RMW_RET_OK != ret) {
RMW_SAFE_FWRITE_TO_STDERR(rmw_get_error_string().str);
RMW_SAFE_FWRITE_TO_STDERR(" during '" RCUTILS_STRINGIFY(__function__) "'\n");
} else {
error_state = *rmw_get_error_state();
ret = inner_ret;
}
rmw_reset_error();
}

if (RMW_RET_OK != ret) {
rmw_set_error_state(error_state.message, error_state.file, error_state.line_number);
}
return rmw_fastrtps_shared_cpp::decrement_context_impl_ref_count(context);

return ret;
}

const rmw_guard_condition_t *
Expand Down
9 changes: 3 additions & 6 deletions rmw_fastrtps_shared_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,26 +131,23 @@ __rmw_destroy_node(
rmw_node_t * node)
{
assert(node->implementation_identifier == identifier);

rmw_ret_t ret = RMW_RET_OK;
auto common_context = static_cast<rmw_dds_common::Context *>(node->context->impl->common);
rmw_dds_common::GraphCache & graph_cache = common_context->graph_cache;
{
std::lock_guard<std::mutex> guard(common_context->node_update_mutex);
rmw_dds_common::msg::ParticipantEntitiesInfo participant_msg =
graph_cache.remove_node(common_context->gid, node->name, node->namespace_);
rmw_ret_t ret = __rmw_publish(
ret = __rmw_publish(
identifier,
common_context->pub,
static_cast<void *>(&participant_msg),
nullptr);
if (RMW_RET_OK != ret) {
return ret;
}
}
rmw_free(const_cast<char *>(node->name));
rmw_free(const_cast<char *>(node->namespace_));
rmw_node_free(node);
return RMW_RET_OK;
return ret;
}

const rmw_guard_condition_t *
Expand Down