-
Notifications
You must be signed in to change notification settings - Fork 306
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
Change the not_composable example to destroy subscription first. #210
Conversation
We are seeing the following message when hitting Ctrl-C in the subscriber not_composable node: [ERROR] [rclcpp]: Error in destruction of rcl subscription handle: the Node Handle was destructed too early. You will leak memory The problem is that setting g_node to nullptr causes the node destructor to be run before the subscriber is destructed. Due to another bug, we can't just remove that assignment, so instead we make it all locally scoped in main for now, which works around the problem. Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
/* We do not recommend this style anymore, because composition of multiple | ||
* nodes in the same executable is not possible. Please see one of the subclass | ||
* examples for the "new" recommended styles. This example is only included | ||
* for completeness because it is similar to "classic" standalone ROS nodes. */ | ||
|
||
void topic_callback(const std_msgs::msg::String::SharedPtr msg) | ||
{ | ||
RCLCPP_INFO(g_node->get_logger(), "I heard: '%s'", msg->data.c_str()) | ||
RCLCPP_INFO(rclcpp::get_logger("minimal_subscriber"), "I heard: '%s'", msg->data.c_str()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the same thing. This function actually does need the node instance to maintain the existing behavior (and the existing behavior is the desired behavior in my opinion).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right, in that case, I've changed it to manually destroy the subscription first, which achieves the same effect. I've also updated the comment. Please take another look when you get a chance.
Signed-off-by: Chris Lalancette <clalancette@openrobotics.org>
We are seeing the following message when hitting Ctrl-C
in the subscriber not_composable node:
[ERROR] [rclcpp]: Error in destruction of rcl subscription handle: the Node Handle was destructed too early. You will leak memory
The problem is that setting g_node to nullptr causes the
node destructor to be run before the subscriber is destructed.
Due to another bug, we can't just remove that assignment, so
instead we make it all locally scoped in main for now, which
works around the problem.
Signed-off-by: Chris Lalancette clalancette@openrobotics.org
This worksaround #209