Closed mauropasse closed 2 years ago
Closing this after closer examination. rclcpp service destructor shouldn't clear the callbacks (neither the rclcpp nor the rmw_..._cpp). It's useless anyway clearing the callbacks since they will be destroyed right away, and no data race could happen since memory is freed in destructor, which means there are no more owners of the service (same applies for all entities). I'll create a PR in rclcpp to remove all of these clearings. Sorry about the noise.
I have identified a data race, produced by the lack of mutual exclusion on entities listeners.
Free listener info:
Then, the same (but could be other) thread on service destruction references memory after it has been freed (thus seg-faults): Update: No other thread could access freed memory, since it would need a living object, in which case the destructor would never have been called (and memory not freed).
1: https://github.com/ros2/rmw_fastrtps/blob/rolling/rmw_fastrtps_shared_cpp/src/rmw_service.cpp#L58 2: https://github.com/ros2/rmw_fastrtps/blob/rolling/rmw_fastrtps_shared_cpp/src/rmw_service.cpp#L132 3: https://github.com/ros2/rmw_fastrtps/blob/rolling/rmw_fastrtps_shared_cpp/src/rmw_service.cpp#L170
Question: Is
CustomServiceInfo *
supposed to be thread safe? Maybe is not possible, and this safety has to be addressed in top layers using it.I'd like to address this issue in the less invasive way, but I'd like suggestions of the correct way to:
For more info, the issue starts here: https://github.com/ros2/rclcpp/blob/3d69031d2a614cf02dc10ea5db153471ea32b1f2/rclcpp/src/rclcpp/service.cpp#L35-L38
In detail:
(*) https://github.com/ros2/rclcpp/blob/3d69031d2a614cf02dc10ea5db153471ea32b1f2/rclcpp/include/rclcpp/service.hpp#L316-L327
So, if we could make sure than in
~ServiceBase()
we callclear_on_new_request_callback()
before the deleter ofservice_handle_
we'd be safe. Or the other approach, removeclear_on_new_request_callback()
call in destructor, which I'm not sure why is there in 1st place, since it might not be necessary.