-
Notifications
You must be signed in to change notification settings - Fork 481
Add ability to disable and enable subscription's callbacks #2985
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
fujitatomoya
left a comment
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.
overall, lgtm.
|
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
left a comment
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.
Rest looks fine.
|
@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 <[email protected]>
Signed-off-by: Michael Orlov <[email protected]>
Signed-off-by: Michael Orlov <[email protected]>
Signed-off-by: Michael Orlov <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
Signed-off-by: Michael Orlov <[email protected]>
- Use spin_some() from the rclcpp::executors::SingleThreadedExecutor directly. Signed-off-by: Michael Orlov <[email protected]>
0361906 to
dcdb56d
Compare
|
@ros-pull-request-builder retest this please |
|
All CI jobs passed green. Merging then. |
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.