Add ability to disable and enable subscription's callbacks#2985
Conversation
|
@ros-pull-request-builder retest this please |
|
Pulls: #2985 |
|
Interesting. The CI failed due to the
Believe me or not, I didn't delete it in this PR ;) |
|
Pulls: #2985 |
😄 My terminal introduced a wierd character, relaunching again |
jmachowinski
left a comment
There was a problem hiding this comment.
Thanks for the patch, I wanted to look into this myself for ages, but just did not find any time...
rclcpp/include/rclcpp/experimental/subscription_intra_process_base.hpp
Outdated
Show resolved
Hide resolved
|
I had a second thought about the current approach, and I think it does not fix the issue, just makes it less likely. The subscriber can be deleted at any point in time, even during the execution of callback. |
But is it really a problem? The callback has its own liveliness time anyway. |
Yes, the problem is that you can't figure out when it is safe to delete the object the callback is pointing to. Lets say you have something like class MyMessageDisapatcher that handles all your callbacks from the subscriber. |
|
@jmachowinski, I see your use case. In your scenario, the problematic part is that you need to delete |
|
@jmachowinski, kindly ping here to reiterate on the review of the last two commits. |
|
Pulls: #2985 |
|
The CI is yellowish, but it seems it is unrelated. |
|
Ahh, I've figured it out. The CI is yellowish due to the new warnings
That is because I was using a deprecated I've just fixed it with the new commit by using spin_some() from the rclcpp::executors::SingleThreadedExecutor |
Signed-off-by: Michael Orlov <morlovmr@gmail.com>
Signed-off-by: Michael Orlov <morlovmr@gmail.com>
Signed-off-by: Michael Orlov <morlovmr@gmail.com>
Signed-off-by: Michael Orlov <morlovmr@gmail.com>
Reasoning: To avoid possible UB when callbacks disabled during callback execution and callback handler object deleted while execution hasn't been finished yet. Signed-off-by: Michael Orlov <morlovmr@gmail.com>
Note: We can't reuse `on_new_event_callback_mutex_` from the EventHandlerBase because those mutex used to protect another type of callbacks. Signed-off-by: Michael Orlov <morlovmr@gmail.com>
Note: While we are temporary removes the on new message callback and all on new event callbacks from the underlying rmw layer to prevent them from being called. We can't guarantee that the currently executing on_new_[message]event callbacks are finished before we exit from the disable_callbacks(). Signed-off-by: Michael Orlov <morlovmr@gmail.com>
Signed-off-by: Michael Orlov <morlovmr@gmail.com>
- Use spin_some() from the rclcpp::executors::SingleThreadedExecutor directly. Signed-off-by: Michael Orlov <morlovmr@gmail.com>
0361906 to
dcdb56d
Compare
|
@ros-pull-request-builder retest this please |
|
All CI jobs passed green. Merging then. |
Explicitly disable all subscription's callbacks to avoid UB and receiving new messages on deleted subscriptions. Note: The callbacks propagated to the executor and may still be in the executor's queue, but they will no longer be called after this point. - Depends on the ros2/rclcpp#2985 Signed-off-by: Michael Orlov <morlovmr@gmail.com>
Explicitly disable all subscription's callbacks to avoid UB and receiving new messages on deleted subscriptions. Note: The callbacks propagated to the executor and may still be in the executor's queue, but they will no longer be called after this point. - Depends on the ros2/rclcpp#2985 Signed-off-by: Michael Orlov <morlovmr@gmail.com>
* Revert "Skip flaky `can_record_again_after_stop` test (#2031)" This reverts commit 5a364f7. Signed-off-by: Michael Orlov <morlovmr@gmail.com> * Explicitly disable subscription's callbacks before its deletion Explicitly disable all subscription's callbacks to avoid UB and receiving new messages on deleted subscriptions. Note: The callbacks propagated to the executor and may still be in the executor's queue, but they will no longer be called after this point. - Depends on the ros2/rclcpp#2985 Signed-off-by: Michael Orlov <morlovmr@gmail.com> --------- Signed-off-by: Michael Orlov <morlovmr@gmail.com>
Description
This PR adds a new API to be able to disable and enable subscription's callbacks.
Is this user-facing behavior change?
Yes. The new API
disable_callbacks()andenable_callbacks()are available for theSubscriptionBaseclass.Did you use Generative AI?
Yes, I am using GitHub Copilot, GPT-5.0 in my workflow to help with Doxygen comments and unit tests.
Additional Information
This PR can't be backported due to the ABI breaking changes. It was added two new virtual functions.