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

Convert all rcl_*_t types to shared pointers #450

Merged

Conversation

guillaumeautran
Copy link
Contributor

Converts all rcl_*_t types in the memory allocation strategy to shared pointers to prevent crash happening when a subscriber is reset.

Issue: #349

@guillaumeautran
Copy link
Contributor Author

FYI: @wjwwood

rcl_reset_error();
}
} else {
RCLCPP_FATAL(
Copy link
Contributor Author

@guillaumeautran guillaumeautran Mar 15, 2018

Choose a reason for hiding this comment

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

changed these to RCLCPP_FATAL (there is no RCLCPP_CRITICAL). Let me know if you would rather have it classified differently.

Copy link
Member

Choose a reason for hiding this comment

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

I would expect FATAL to exit the process. I'd use ERROR instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing.

@mikaelarguedas mikaelarguedas added the in review Waiting for review (Kanban column) label Mar 15, 2018
rcl_reset_error();
}
} else {
RCLCPP_FATAL(
Copy link
Member

Choose a reason for hiding this comment

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

I would expect FATAL to exit the process. I'd use ERROR instead.

if (handle) {
if (rcl_client_fini(client, handle.get()) != RCL_RET_OK) {
RCLCPP_ERROR(
rclcpp::get_logger(rcl_node_get_name(handle.get())).get_child("rclcpp"),
Copy link
Member

Choose a reason for hiding this comment

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

I may have missed this also on the previous review, but I think you should use rcl_node_get_logger_name here rather than rcl_node_get_name, which will not include the node's namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do.


std::shared_ptr<rcl_client_t> client_handle_;
std::shared_ptr<rcl_node_t> node_handle_;
Copy link
Member

Choose a reason for hiding this comment

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

Is this order change important? Otherwise I'd ask you to leave it as-is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want the client handle to be destructed before the node handle. I agree that relying on implicit class destruction is naive. I'll make it explicit in the ClientBase desctructor.

@@ -118,16 +116,25 @@ class Service : public ServiceBase
using rosidl_typesupport_cpp::get_service_type_support_handle;
auto service_type_support_handle = get_service_type_support_handle<ServiceT>();

std::weak_ptr<rcl_node_t> weak_node_handle(node_handle_);
// rcl does the static memory allocation here
service_handle_ = std::shared_ptr<rcl_service_t>(
new rcl_service_t, [ = ](rcl_service_t * service)
Copy link
Member

Choose a reason for hiding this comment

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

I let this slide in the last review, but I actually think the implicit copy capture here is dangerous, because it also captures this, and therefore it's too each to accidentally use something from this inside the lambda in the future which will compile and work until the case where you delete the class but something else has a handle to the rcl_service_t (applies to each of the entity types).

I'd feel better about it with explicitly listing what you need to capture by copy or reference, rather than using one of the catch all ones. So in this case it should be just [weak_node_handle].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem. Changing...

@@ -80,7 +88,8 @@ ClientBase::service_is_ready() const
{
bool is_ready;
rcl_ret_t ret =
rcl_service_server_is_available(this->get_rcl_node_handle(), client_handle_.get(), &is_ready);
rcl_service_server_is_available(
this->get_rcl_node_handle(), get_client_handle().get(), &is_ready);
Copy link
Member

Choose a reason for hiding this comment

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

Please do not wrap both the right hand side of an assignment as well as the arguments, but if you have to, make sure to indent the arguments again. Also please use this-> with methods of this class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I understand what you are asking but if not, let me know.

Converts all rcl_*_t types in the memory allocation strategy to shared pointers to prevent crash happening when a subscriber is reset.

Issue: ros2#349
@wjwwood wjwwood merged commit e2c1658 into ros2:revert-448-revert-431-issue-349 Mar 19, 2018
@wjwwood wjwwood removed the in review Waiting for review (Kanban column) label Mar 19, 2018
nnmm pushed a commit to ApexAI/rclcpp that referenced this pull request Jul 9, 2022
Signed-off-by: Ralf Anton Beier <ralf_beier@me.com>
DensoADAS pushed a commit to DensoADAS/rclcpp that referenced this pull request Aug 5, 2022
* added db directory creation to storage factory

Signed-off-by: Marwan Taher <marokhaled99@gmail.com>

* moved db directory creation to rosbag2_cpp

Signed-off-by: Marwan Taher <marokhaled99@gmail.com>

* rasing exception if dir already exists

Signed-off-by: Marwan Taher <marokhaled99@gmail.com>

* removed dir creation from record.py, added dir creation to sequential_compression_writer and refactored dir creation in sequential_writer

Signed-off-by: Marwan Taher <marokhaled99@gmail.com>

* fixed failing tests

Signed-off-by: Marwan Taher <marokhaled99@gmail.com>

* fixing review comments

Signed-off-by: Marwan Taher <marokhaled99@gmail.com>

* Apply suggestions from code review

Co-authored-by: Karsten Knese <Karsten1987@users.noreply.github.com>
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.

None yet

3 participants