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

Fixes to support proper lifecycle of the rmw objects and other tear down issues #51

Merged
merged 6 commits into from
Jul 15, 2015

Conversation

wjwwood
Copy link
Member

@wjwwood wjwwood commented Jun 29, 2015

While prototyping the intra-process system I ran into some blocking teardown issues that manifested in my multi node examples during runtime. So I had to fix them. This will be matched with pr's on rmw and the implementations.

Connects ros2/ros2#69

@wjwwood wjwwood added the in progress Actively being worked on (Kanban column) label Jun 29, 2015
@esteve
Copy link
Member

esteve commented Jun 29, 2015

+1

if (rmw_destroy_client(client_handle_) == RMW_RET_ERROR) {
std::cerr << "Error in destruction of rmw client handle: " <<
(rmw_get_error_string() ? rmw_get_error_string() : "") <<
std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

uneven indent?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's what uncrustify does this to it... I'm pretty nonplussed about it's ability to handle some of these cases, but I don't have time to look into why it does that or come up with another solution. I guess I can add the comments around it to disable the check.

@tfoote
Copy link
Contributor

tfoote commented Jun 30, 2015

+1

This prevents the node handle from getting
deleted before things it created can be deleted.

I also added destructors where necessary.
if (rmw_destroy_client(client_handle_) == RMW_RET_ERROR) {
// *INDENT-OFF*
std::cerr << "Error in destruction of rmw client handle: "
<< (rmw_get_error_string() ? rmw_get_error_string() : "")
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. If the error string is unavailable, should the ternary statement instead return something like "RMW error unknown"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe it should be something like "error string not set". In reality the else case shouldn't happen, this is just defensive so that we don't trying to send a null pointer to std::cerr.

I also think we should encapsulate this logic in a function, maybe rmw_get_error_string_safe or something like that, where it would guarantee that cstring is returned ("" or "error string not set") and a null pointer is not. Currently it can return null if it is not set.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for putting it in a function, since it's repeated several places in this code.

Copy link
Member Author

Choose a reason for hiding this comment

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

I made it into a function, const char * rmw_get_error_string_safe(). I'm open to different names (should be easy to change it).

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh and it returned "error string not set" rather than "", so that will change existing behavior in a few places, but it shouldn't make a difference.

std::shared_ptr<rmw_node_t> node_handle,
rmw_client_t * client_handle,
const std::string & service_name)
: node_handle_(node_handle), client_handle_(client_handle), service_name_(service_name)
{}

~ClientBase()
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated to the PR itself but probably necessary for cleaning up user created instances:

Shouldn't the destructor be virtual? (same for multiple other classes)

@wjwwood
Copy link
Member Author

wjwwood commented Jul 2, 2015

I think all of the comments have been addressed.

@jacquelinekay
Copy link
Contributor

+1

rmw_destroy_client(client_handle_);
client_handle_ = nullptr;
if (client_handle_) {
if (rmw_destroy_client(client_handle_) == RMW_RET_ERROR) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we stick to one pattern? E.g. rmw_*(..) != RMW_RET_OK.

Copy link
Member Author

Choose a reason for hiding this comment

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

5921c35

@dirk-thomas
Copy link
Member

+1 for squash and merge.

As a follow up I would replace the usage of stringstream for error messages with fprintf.

wjwwood added a commit that referenced this pull request Jul 15, 2015
Fixes to support proper lifecycle of the rmw objects and other tear down issues
@wjwwood wjwwood merged commit 62fcb37 into master Jul 15, 2015
@wjwwood wjwwood removed the in progress Actively being worked on (Kanban column) label Jul 15, 2015
@wjwwood wjwwood deleted the memory_audit branch July 15, 2015 21:23
nnmm pushed a commit to ApexAI/rclcpp that referenced this pull request Jul 9, 2022
* check rmw id using RCL_CHECK_RMW_ID_MATCHES_OR_DIE

* return a more distinct return code on mismatch

* rename env var to RCL_ASSERT_RMW_ID_MATCHES

* [style] fixup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants