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

Do not clear entities callbacks on destruction #2002

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion rclcpp/include/rclcpp/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class ClientBase
rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph);

RCLCPP_PUBLIC
virtual ~ClientBase();
virtual ~ClientBase() = default;

/// Take the next response for this client as a type erased pointer.
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class SubscriptionIntraProcessBase : public rclcpp::Waitable
{}

RCLCPP_PUBLIC
virtual ~SubscriptionIntraProcessBase();
virtual ~SubscriptionIntraProcessBase() = default;

RCLCPP_PUBLIC
size_t
Expand Down
2 changes: 1 addition & 1 deletion rclcpp/include/rclcpp/service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ServiceBase
explicit ServiceBase(std::shared_ptr<rcl_node_t> node_handle);

RCLCPP_PUBLIC
virtual ~ServiceBase();
virtual ~ServiceBase() = default;

/// Return the name of the service.
/** \return The name of the service. */
Expand Down
7 changes: 0 additions & 7 deletions rclcpp/src/rclcpp/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ ClientBase::ClientBase(
});
}

ClientBase::~ClientBase()
{
clear_on_new_response_callback();
// Make sure the client handle is destructed as early as possible and before the node handle
client_handle_.reset();
}

bool
ClientBase::take_type_erased_response(void * response_out, rmw_request_id_t & request_header_out)
{
Expand Down
5 changes: 0 additions & 5 deletions rclcpp/src/rclcpp/publisher_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ PublisherBase::PublisherBase(

PublisherBase::~PublisherBase()
{
for (const auto & pair : event_handlers_) {
rcl_publisher_event_type_t event_type = pair.first;
clear_on_new_qos_event_callback(event_type);
}

// must fini the events before fini-ing the publisher
event_handlers_.clear();

Expand Down
4 changes: 0 additions & 4 deletions rclcpp/src/rclcpp/qos_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ UnsupportedEventTypeException::UnsupportedEventTypeException(

QOSEventHandlerBase::~QOSEventHandlerBase()
{
if (on_new_event_callback_) {
clear_on_ready_callback();
}

if (rcl_event_fini(&event_handle_) != RCL_RET_OK) {
RCUTILS_LOG_ERROR_NAMED(
"rclcpp",
Expand Down
4 changes: 0 additions & 4 deletions rclcpp/src/rclcpp/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ ServiceBase::ServiceBase(std::shared_ptr<rcl_node_t> node_handle)
node_logger_(rclcpp::get_node_logger(node_handle_.get()))
{}

ServiceBase::~ServiceBase()
{
clear_on_new_request_callback();
Copy link
Collaborator

Choose a reason for hiding this comment

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

std::shared_ptr<rcl_service_t> service_handle_ will be deleted after clear_on_new_request_callback(), right? All member variables are alive in the body of the destructor. So this is something like optimization?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, usually that's the order. But I found a strange case with lifecycle nodes destruction, where it happens in the opposite order!
Anyway, even if the order were correct, IMO there is no real point in clearing those callbacks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

i think that this should not be called here, because it might generate the exception in dtor.

see,

https://github.com/ros2/rmw/blob/rolling/rmw/include/rmw/rmw.h#L3118-L3131

if the callback is NULL, as specification, it is supposed to return RMW_RET_INVALID_ARGUMENT.
and eventually rclcpp will generate rclcpp::exceptions::throw_from_rcl_error.

test is pass cz rmw_fastrtps always return RCL_RET_OK. (this is not correct behavior based on the doc.)

if we use RTI Coneext DDS, the test fails as following, because it returns RMW_RET_UNSUPPORTED.

[ RUN      ] TestService.on_new_request_callback
RTI Connext DDS Non-commercial license is for academic, research, evaluation and personal use only. USE FOR COMMERCIAL PURPOSES IS PROHIBITED. See RTI_LICENSE.TXT for terms. Download free tools at rti.com/ncl. License issued to Non-Commercial User license@rti.com For non-production use only.
Expires on 00-jan-00 See www.rti.com for more information.
[ERROR] [1661535719.598830456] [rmw_connextdds]: rmw_service_set_on_new_request_callback not implemented
unknown file: Failure
C++ exception with description "failed to set the on new request callback for service: rmw_service_set_on_new_request_callback not implemented, at /root/ros2_ws/colcon_ws/src/ros2/rmw_connextdds/rmw_connextdds_common/src/common/rmw_listener.cpp:45" thrown in the test body.
[  FAILED  ] TestService.on_new_request_callback (315 ms)

after all, i think after this PR is merged, we need to re-check the listener rmw implementation and extend test for all rmw tier 1 implementation. what do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good, you found a better reason for removing these calls! And yes I agree, tests should be extended for these calls to return the other possible values too. When I found some time I'll add them. You have any other ideas for testing?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can manage the following with different PR,

  • test all tier 1 rmw implementations with listener APIs for rclcpp (rclpy does not support?)
  • bugfix rmw implementations if necessary, i think rmw_connextdds is the correct implementation.
  • test would be required to adjust accordingly.

}

bool
ServiceBase::take_type_erased_request(void * request_out, rmw_request_id_t & request_id_out)
Expand Down
7 changes: 0 additions & 7 deletions rclcpp/src/rclcpp/subscription_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ SubscriptionBase::SubscriptionBase(

SubscriptionBase::~SubscriptionBase()
{
clear_on_new_message_callback();

for (const auto & pair : event_handlers_) {
rcl_subscription_event_type_t event_type = pair.first;
clear_on_new_qos_event_callback(event_type);
}

if (!use_intra_process_) {
return;
}
Expand Down
5 changes: 0 additions & 5 deletions rclcpp/src/rclcpp/subscription_intra_process_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@

using rclcpp::experimental::SubscriptionIntraProcessBase;

SubscriptionIntraProcessBase::~SubscriptionIntraProcessBase()
{
clear_on_ready_callback();
}

void
SubscriptionIntraProcessBase::add_to_wait_set(rcl_wait_set_t * wait_set)
{
Expand Down
1 change: 0 additions & 1 deletion rclcpp_action/src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ ClientBase::ClientBase(

ClientBase::~ClientBase()
{
clear_on_ready_callback();
}

bool
Expand Down
1 change: 0 additions & 1 deletion rclcpp_action/src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ ServerBase::ServerBase(

ServerBase::~ServerBase()
{
clear_on_ready_callback();
}

size_t
Expand Down