-
Notifications
You must be signed in to change notification settings - Fork 429
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
Publishing right before shutdown due to SIGINT #1706
Comments
So, having a callback before shutdown is pretty straightforward, we would just need to add a second loop through the callbacks before shutdown here: rclcpp/rclcpp/src/rclcpp/context.cpp Lines 310 to 323 in e9e398d
As you suggested, with either a flag to However, I'm not sure a pre-shutdown callback will be sufficient. If you publish and then shutdown and then (presumably) continue by shutting the process down immediately, you may never send the published message, because publishing may be done asynchronously or not depending on the middleware implementation. This is why people are working on this issue: ros2/rmw#295 ("Add ability to confirm reader receive all sent messages"). You could use something like this in an "on shutdown" callback, but you wouldn't want to block for too long as you'd be holding up all the other callbacks and the shutdown of other contexts. |
But either way a feature to do callbacks pre-shutdown might be generally useful. |
It would be intuitive if messages from reliable publishers are always delivered, even if the publication is immediately followed by |
It is good to add callback of pre-shutdown. |
It would not be intuitive if publishers prevent processes from exiting though. What happens in the case that the process with the subscription crashes and doesn't respond to ack/nak from the publisher? How long does it stay open trying to deliver it? I think it's better if this is documented and then we provide some way to keep the process alive, IF that is what the user wants. I'm still not convinced that delaying shutdown by blocking on |
I tried to create a minimal example that illustrates the current behavior (Foxy) of a reliable publisher and subscriber, in case the publisher shuts down immediately after publishing: https://gist.github.com/erikschuitema/249677e36f233fc421d1e0087d301668 Run the publisher with The example above can execute an arbitrary sleep after publication, which changes the behavior. For example, run the publisher as @wjwwood to answer your question: my personal view is that if I configure a publisher to be reliable, it's perfectly fine if it hangs a limited amount of time upon exiting due to a crashed subscriber. I don't see a 'liveliness' parameter for subscribers, unfortunately. Crashed subscribers are not the common case for me. If I really need the publisher to terminate, I can send SIGKILL. |
#1714 is merged, and once ros2/examples#316 and friends are merged, you can choose to do this yourself. But I still do not think we should do this automatically. I'm going to close this issue, but we can continue to discuss it and if other maintainers jump in and disagree we can reopen it. |
Feature request
Feature description
Sometimes it is useful to publish messages right before shutting down, for example, a (lifecycle) state change message.
If a node shuts down due to a SIGINT signal and uses the default signal handler, the global context is shutdown as well. If
rclcpp::spin(node)
is used insidemain()
and SIGINT ends it, any code following it cannot publish because of this.The callbacks installed with
rclcpp::on_shutdown()
are called after the shutdown, so this is also not the place to publish.Currently, the only possible way I could find is to install a signal handler before
rclcpp::init()
, which will be stored as the 'old' signal handler inside therclcpp::SignalHandler
singleton when it installs the default handler. This 'old' handler does get called before actually shutting down.Since signal handlers are fairly limited and typically require global variables to do anything useful, it would be a nice feature if callbacks could be installed that are called before a shutdown.
Implementation considerations
One option would be to have
rclcpp::on_shutdown()
accept an option to specify that the callback be called either before or after shutting down.This implies that the callback is executed before/after any call to
rclcpp::shutdown()
, instead of only after SIGINT, but this could actually be an advantage.The text was updated successfully, but these errors were encountered: