You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Asynchronously shutting down while using rclcpp::spinrclcpp:spin_some in another thread throws an exception #1139
What is happening is that one thread is creating an executor, while other is trying to shutdown.
If shutdown is called before the creation of the Executor, an exception is thrown:
Seems like user error; calling shutdown before spin. What's an alternative, have spin return if the context is invalid?
The thing is that spin_some is called in a loop, "protected" in a rclcpp::ok check.
If the context is shutdown in the middle of the call to rclcpp::ok and the construction of the executor in rclcpp::spin_some, then the error happens.
IMO, it's a behavior error, and not an user one (I would expect that if I do something after checking for rclcpp::ok, there should be no problem).
IMO shutdown shouldn't affect executors/publishers/subscriptions/nodes/... etc, it should only make rclcpp::ok() return false and wake up executors.
In that way, we could shutdown asynchronously without this error (or other bunch of possible of similar errors).
Originally I thought about shutdown like KeyboardInterrupt in Python, but since this is C++ and the user isn't always inside on of our functions we cannot ensure it is raised everywhere. Instead we have (some of ) our functions raise and then the user can check rclcpp::ok() to know when to interrupt their own work.
The thinking was that if the user wrote something like this:
while (true) {
rclcpp::spin_some(...);
}
Then they wouldn't get stuck in a loop due the mistake (imo) of not checking rclcpp::ok(). I think this fail fast approach will result in the fewest unexplained hangs for users.
However, that means to avoid tracebacks and crashes they need to catch and handle these errors (like you do with KeyboardInterrupt in Python), and it's also hard to know which things will work and which will not. For example, publishing will work, and destroying a publisher will work, but making a new publisher will not. This was essentially a compromise to enable things like "during shutdown I might want to send a message (publish) to notify someone", for example.
The rules not being clear on this is something that Apex folks struggled with, and it's clearly been an issue for us and our users. So I'd be open to reevaluating this decision. We could instead say that shutdown changes nothing but a flag in the context, and everything continues as normal and it's up to the user to notice and react to it.
IMO, it's a behavior error, and not an user one (I would expect that if I do something after checking for rclcpp::ok, there should be no problem).
This is a bad assumption, imo. It's like acquiring a lock, releasing it, and then assuming afterwards the resource is safe. I understand how it's an easy mistake to make, but imo it is a mistake. rclcpp::ok() just checks a state, it doesn't hold a resource or block other actions, and it doesn't indicate that to be the case.
Thanks for pointing out the duplicates.
I will try to consolidate all of them in a new issue --or edit an old one--, and close the others.
Then they wouldn't get stuck in a loop due the mistake (imo) of not checking rclcpp::ok(). I think this fail fast approach will result in the fewest unexplained hangs for users.
However, that means to avoid tracebacks and crashes they need to catch and handle these errors (like you do with KeyboardInterrupt in Python), and it's also hard to know which things will work and which will not. For example, publishing will work, and destroying a publisher will work, but making a new publisher will not. This was essentially a compromise to enable things like "during shutdown I might want to send a message (publish) to notify someone", for example.
The rules not being clear on this is something that Apex folks struggled with, and it's clearly been an issue for us and our users. So I'd be open to reevaluating this decision. We could instead say that shutdown changes nothing but a flag in the context, and everything continues as normal and it's up to the user to notice and react to it.
I think that both "exception like" and "notification like" behaviors are acceptable and have their pro/cons. But IMO, we're doing neither of both correctly.
If we prefer throwing an exception when the user tries "doing something" after shutdown, I think we should everywhere throw the same exception.
e.g.: In the case I pointed out, we're just throwing an RCLError with a custom message, how do I distinguish that from an actual error?
I also think that we should add the try/catch in our examples/demos.
That's exactly what I don't like of how shutdown works right now, you only can try/catch a generic RCLError. There should be a rclcpp::exceptions::Shutdown error (or similar).
We could then add in rclcpp a ShutdownError derived from RCLError and make sure we throw that one in throw_from_rcl_error. In rclpy, we should make sure to always raise KeybordInterrupt in those cases.
I think that with those changes, we will be able to handle an asynchronous shutdown gracefully.
This approach requires careful reviewing of all functions in rcl layer, to make sure they are returning the appropriate error (and careful handling of those errors in the upper client layer).
Note: It's impossible to recognize an already shutdown context of one that was never init, that should be clear in error messages.
i think that is feasible. one question, what is the difference between RCL_RET_IS_SHUTDOWN and RCL_RET_CONTEXT_INVALID? i was thinking RCL_RET_CONTEXT_INVALID is equal to RCL_RET_IS_SHUTDOWN. we should add specific state that tells us if shutdown is called or not? could you enlighten me a little bit?
i think that is feasible. one question, what is the difference between RCL_RET_IS_SHUTDOWN and RCL_RET_CONTEXT_INVALID?
Sorry, I think my comment wasn't clear.
Those are two names suggestions for the same new return code. RCL_RET_CONTEXT_INVALID is named similarly to the other return codes. RCL_RET_IS_SHUTDOWN is a more clear name for this case IMO.
I think we should consider and address the bigger picture: how should a user perform multiple init / shutdown cycles cleanly? Atm the shutdown() call isn't blocking and you can't call init() right afterwards without being subject to a race or warnings like "logging already initialized".
shutdown() call isn't blocking and you can't call init() right afterwards without being subject to a race or warnings like "logging already initialized".
i think that we can, and shutdown() call blocks with
I think we should consider and address the bigger picture: how should a user perform multiple init / shutdown cycles cleanly?
It should be safe to do it after rclcpp::ok() returns false.
Atm the shutdown() call isn't blocking and you can't call init() right afterwards without being subject to a race or warnings like "logging already initialized".
We're currently finishing loggers at shutdown (see here), and I think that part of the idea is to stop doing that and doing it when the context is destructed.
If we do that change, init should make sure to handle the problem correctly (it's possible with some extra lines here).
We could also provide a reinit method that takes no arguments. It will make sure that the context is valid again, and it uses the same init options passed before (i.e. it only switches a flag).
examples:
rclcpp::init(argc, argv, init_options);
while (rclcpp::ok()) {
executor.spin_all(max_duration);
... handle more work here
}
rclcpp::reinit();
auto context = rclcpp::Context::make_shared();
context->init(argc, argv, init_options);
while (context->is_valid()) {
executor.spin_all(max_duration);
... handle more work here
}
context->init(other_argc, other_argv, other_init_options);
We should make sure both examples above work.
If the user is trying to call rclcpp::Context::init from more than one thread, it will be a problem.
But I don't think we should provide such thread safety guarantee.
It should be safe to do it after rclcpp::ok() returns false.
It's not though... It's only safe to do that after the context is destructed right?
I haven't tried it recently, but you should be able to init/shutdown contexts in parallel as long as you're using different ones each time. Maybe the global logging setup doesn't make that work anymore.
It's not though... It's only safe to do that after the context is destructed right?
I think it's currently safe, as shutdown is finishing the logger and init will be able to setup it again correctly (supposing only one context).
If we move logging finishing to context destruction, we will need to handle that case in init.
I haven't tried it recently, but you should be able to init/shutdown contexts in parallel as long as you're using different ones each time. Maybe the global logging setup doesn't make that work anymore.
It should work if one context initializes the logging system and the other doesn't.
I think it would be great to move the global context configuration to one per Context, but that doesn't seem to be exactly related (I will create an issue and add it to the Galactic project board).
I think we should add test for all these cases when doing the change, so it will be clear what works and what doesn't.
Both cases can conceptually work correctly with the change in shutdown behavior.
If the context is shutdown in the middle of the call to rclcpp::ok and the construction of the executor in rclcpp::spin_some, then the error happens.
IMO, it's a behavior error, and not an user one (I would expect that if I do something after checking for rclcpp::ok, there should be no problem).
I see. It's a valid point. Perhaps spinning a entity associated with a shutdown context shouldn't throw an exception?
Quoting myself, I think this might be the right path to take. Just make it so that shutdown does not affect the function of anything, it simply changes the state of rclcpp::Context::ok()/rclcpp::ok().
I guess the question is, what's the point of having a third shutdown state besides the usual init-fini cycle? If we only intend it to be a generic notification with no side-effects of its own, why making it a separate state? Why restricting it to a single event? Why do we call it shutdown?
As I see it, to shutdown means a context and all entities associated with it are soon to be finalized. That certainly bans entity creation and restricts the amount of work you can do (spinning is a good example of what should be allowed, or otherwise the added state is somewhat useless). And while we don't do anything meaningful about it right now, if anyone ever wants to:
Hint the system that an entity is on its way out
To avoid spurious service requests (way faster than a timeout).
To exclude them from discovery entirely (in DDS, or whatever transport protocol rmw uses)
Reschedule entity tasks to speed up termination.
Free/redistribute resource pools early
we'll need the concept.
I think we should consider and address the bigger picture: how should a user perform multiple init / shutdown cycles cleanly?
It should be safe to do it after rclcpp::ok() returns false.
It's not though... It's only safe to do that after the context is destructed right?
I think it's currently safe, as shutdown is finishing the logger and init will be able to setup it again correctly (supposing only one context).
I will say that's because rclcpp::Context::init silently destroys the underlying rcl context. Below rclcpp, it's init-shutdown-fini and only then a context can be reused.
Note: It's impossible to recognize an already shutdown context of one that was never init, that should be clear in error messages.
This is true because rcl uses an atomic flag to invalidate contexts, instead of relying on rmw which also has to track shutdown contexts (to comply with rmw_context_fini() API). Finalized and shutdown context states could be perfectly distinguishable.
As I see it, to shutdown means a context and all entities associated with it are soon to be finalized.
That's what I imagined as well, but I think there's a need for another use case too, but whether or not that should be part of the same mechanism, I'm not sure. For example, we need a "you should stop, cleanup, and exit your node's main functions". That's what shutdown() meant in ROS 1 for the most part.
Yeah, I see it. I'm just not convinced that's Context::shutdown() purpose. And for the record, I'm not advocating for having both if we don't think it's worth the effort. Perhaps what we're looking for is some Context::interrupt() primitive?
That's what I imagined as well, but I think there's a need for another use case too, but whether or not that should be part of the same mechanism, I'm not sure. For example, we need a "you should stop, cleanup, and exit your node's main functions". That's what shutdown() meant in ROS 1 for the most part.
In ROS 1, calling shutdown from a different thread was safe.
A lots of the functions were a noop after shutdown happen, and didn't raise an exception.
e.g:
If you called spin after shutdown, it returned immediately.
I'm not completely sure, but I think you could even create a "Publisher" after shutdown (it wasn't going to really advertise anything, but trying to create one wouldn't fail).
Based on that, I think that the current ROS 2 shutdown behavior isn't quite the same.
As I see it, to shutdown means a context and all entities associated with it are soon to be finalized.
Sure, but that doesn't mean that shutdown should destroy things or make things raise an unknown exception IMO.
Yeah, I see it. I'm just not convinced that's Context::shutdown() purpose. And for the record, I'm not advocating for having both if we don't think it's worth the effort. Perhaps what we're looking for is some Context::interrupt() primitive?
IMHO, it's not a good idea to add a different method that it's similar and doesn't do exactly the same that shutdown (except if we have a strong use case for that).
The problem is that shutdown isn't thread safe, and it was thread safe in ROS 1.
I think that we should fix that first. We can add a different mechanism later if we find the need.
Sure, but that doesn't mean that shutdown should destroy things or make things raise an unknown exception IMO.
Agree about not destroying things, and raising unknown exceptions is never an option. But that happens because we don't deal with shutdowns properly yet.
IMHO, it's not a good idea to add a different method that it's similar and doesn't do exactly the same that shutdown (except if we have a strong use case for that).
The problem is that shutdown isn't thread safe, and it was thread safe in ROS 1.
I can't argue about the need for use cases. And I agree that it should be made thread-safe. What I'm calling out, based on the preceding discussion, is the attempt to turn shutdown into something conceptually different in the process. If the plan to make it thread-safe is to make it a flag and leave side-effects to calling code, that's fair, but don't call it shutdown (just like KeyboardInterrupt isn't ShutdownRequest even though that's the typical use case). I don't even see the need for a separate context state really if that's all we want from it.
But that happens because we don't deal with shutdowns properly yet.
What does "dealing with shutdowns properly" mean?
I think that's the main question here, and I'm failing to get a consensus of what it means.
If the plan to make it thread-safe is to make it a flag and leave side-effects to calling code, that's fair, but don't call it shutdown (just like KeyboardInterrupt isn't ShutdownRequest even though that's the typical use case). I don't even see the need for a separate context state really if that's all we want from it.
AFAIS, in ROS 1 it was actually a flag.
After that flag was true, some things start behaving as a noop but never retrieved an error.
I don't even see the need for a separate context state really if that's all we want from it.
I'm not sure what "separate context state" is referring to.
just like KeyboardInterrupt isn't ShutdownRequest even though that's the typical use case
I would say that a KeyboardInterrupt can be considered a ShutdownRequest, but not the opposite way around.
We will probably need to set up a meeting to discuss this, as this discussion is getting quite long.
We will probably need to set up a meeting to discuss this, as this discussion is getting quite long.
Agreed.
But to entertain the discussion:
What does "dealing with shutdowns properly" mean?
IMHO to have APIs behave in a well-defined, thread-safe, and documented way when a shutdown occurs (no random exception, no UB, etc.).
AFAIS, in ROS 1 it was actually a flag.
After that flag was true, some things start behaving as a noop but never retrieved an error.
I'm not onboard with how ROS 1 did lots of things. Whether ROS 2 should mimic for the sake of familiarity or depart in an attempt to improve is a somewhat philosophical discussion.
I'm not sure what "separate context state" is referring to.
To have an invalidated context as a notification, instead of simply sending a notification.
We should definitely have some meetings to nail this down.
With respect to the topic of emulating ROS 1 or not in this case, I think we shouldn't. This is mostly based on my experience with clients like Apex, where consistent behavior is key, and having a variety of reactions from the API when shutdown is called makes it hard to know (without 100% familiarity with the entire API) what will happen.
To that end, I think the best idea is just making shutdown a flag, and have none of our API change its behavior when that occurs, instead, allowing the user to decide how to detect/check for it and handle it.
If there is then cases which are common place and are becoming boilerplate, we can add convenience to reduce code duplication, but should ideally be opt-in so the default behavior is predictable and unsurprising, even if they're a bit inconvenient.
This is just all my opinion at this point, and I definitely not sure it's the correct path, but we should discuss it and come to some consensus. 👍
Activity
ivanpauno commentedon May 27, 2020
@hidmic @wjwwood @jacobperron does this look like an user error (i.e. the test is not well written) or should be improve how shutdown works?
hidmic commentedon May 27, 2020
I'd say user error.
jacobperron commentedon May 27, 2020
Seems like user error; calling shutdown before spin. What's an alternative, have spin return if the context is invalid?
ivanpauno commentedon May 27, 2020
The thing is that
spin_someis called in a loop, "protected" in arclcpp::okcheck.If the context is shutdown in the middle of the call to
rclcpp::okand the construction of the executor inrclcpp::spin_some, then the error happens.IMO, it's a behavior error, and not an user one (I would expect that if I do something after checking for
rclcpp::ok, there should be no problem).IMO shutdown shouldn't affect executors/publishers/subscriptions/nodes/... etc, it should only make
rclcpp::ok()return false and wake up executors.In that way, we could shutdown asynchronously without this error (or other bunch of possible of similar errors).
wjwwood commentedon May 27, 2020
I also would classify it as "user error", but not necessarily the user's fault. It's confusing and so the existing story could be improved.
This has been discussed in the past:
And perhaps others, though I couldn't find them. I know @sloretz and I spoke about it in person at length around the time ros2/rmw#154 was merged.
And this might be a duplicate?
Originally I thought about shutdown like KeyboardInterrupt in Python, but since this is C++ and the user isn't always inside on of our functions we cannot ensure it is raised everywhere. Instead we have (some of ) our functions raise and then the user can check
rclcpp::ok()to know when to interrupt their own work.The thinking was that if the user wrote something like this:
Then they wouldn't get stuck in a loop due the mistake (imo) of not checking
rclcpp::ok(). I think this fail fast approach will result in the fewest unexplained hangs for users.However, that means to avoid tracebacks and crashes they need to catch and handle these errors (like you do with KeyboardInterrupt in Python), and it's also hard to know which things will work and which will not. For example, publishing will work, and destroying a publisher will work, but making a new publisher will not. This was essentially a compromise to enable things like "during shutdown I might want to send a message (publish) to notify someone", for example.
The rules not being clear on this is something that Apex folks struggled with, and it's clearly been an issue for us and our users. So I'd be open to reevaluating this decision. We could instead say that shutdown changes nothing but a flag in the context, and everything continues as normal and it's up to the user to notice and react to it.
wjwwood commentedon May 27, 2020
This is a bad assumption, imo. It's like acquiring a lock, releasing it, and then assuming afterwards the resource is safe. I understand how it's an easy mistake to make, but imo it is a mistake.
rclcpp::ok()just checks a state, it doesn't hold a resource or block other actions, and it doesn't indicate that to be the case.ivanpauno commentedon May 28, 2020
Transferred the issue to
rclcpp, as I opened it inrmwby mistake.ivanpauno commentedon May 28, 2020
Thanks for pointing out the duplicates.
I will try to consolidate all of them in a new issue --or edit an old one--, and close the others.
I think that both "exception like" and "notification like" behaviors are acceptable and have their pro/cons. But IMO, we're doing neither of both correctly.
If we prefer throwing an exception when the user tries "doing something" after shutdown, I think we should everywhere throw the same exception.
e.g.: In the case I pointed out, we're just throwing an
RCLErrorwith a custom message, how do I distinguish that from an actual error?I also think that we should add the
try/catchin our examples/demos.fujitatomoya commentedon May 29, 2020
@ivanpauno
Just FYI, I think that I already did it with ros2/examples#270.
ivanpauno commentedon May 29, 2020
That's exactly what I don't like of how
shutdownworks right now, you only cantry/catcha genericRCLError. There should be arclcpp::exceptions::Shutdownerror (or similar).ivanpauno commentedon Jun 22, 2020
We already have in
rclreturn values likeRCL_RET_NODE_INVALID,RCL_RET_PUBLISHER_INVALID, etc.After shutdown, you usually get one of those errors (e.g. https://github.com/ros2/rcl/blob/069d1f07290019b62a8297c5f95a80b58e63682a/rcl/src/rcl/publisher.c#L286).
Can we add a
RCL_RET_IS_SHUTDOWNorRCL_RET_CONTEXT_INVALIDinrcland return that when appropriate?We could then add in rclcpp a
ShutdownErrorderived from RCLError and make sure we throw that one in throw_from_rcl_error. In rclpy, we should make sure to always raise KeybordInterrupt in those cases.I think that with those changes, we will be able to handle an asynchronous shutdown gracefully.
This approach requires careful reviewing of all functions in
rcllayer, to make sure they are returning the appropriate error (and careful handling of those errors in the upper client layer).Note: It's impossible to recognize an already shutdown context of one that was never init, that should be clear in error messages.
fujitatomoya commentedon Jun 23, 2020
i think that is feasible. one question, what is the difference between RCL_RET_IS_SHUTDOWN and RCL_RET_CONTEXT_INVALID? i was thinking RCL_RET_CONTEXT_INVALID is equal to RCL_RET_IS_SHUTDOWN. we should add specific state that tells us if shutdown is called or not? could you enlighten me a little bit?
ivanpauno commentedon Jun 23, 2020
Sorry, I think my comment wasn't clear.
Those are two names suggestions for the same new return code.
RCL_RET_CONTEXT_INVALIDis named similarly to the other return codes.RCL_RET_IS_SHUTDOWNis a more clear name for this case IMO.fujitatomoya commentedon Jun 24, 2020
@ivanpauno
thanks for the clarification, we will take care of this.
8 remaining items
dirk-thomas commentedon Jun 30, 2020
I think we should consider and address the bigger picture: how should a user perform multiple
init/shutdowncycles cleanly? Atm theshutdown()call isn't blocking and you can't callinit()right afterwards without being subject to a race or warnings like "logging already initialized".fujitatomoya commentedon Jul 1, 2020
i think that we can, and
shutdown()call blocks withrclcpp/rclcpp/include/rclcpp/context.hpp
Line 345 in a8cd936
maybe i am misunderstanding, could you elaborate?
ivanpauno commentedon Jul 1, 2020
It should be safe to do it after
rclcpp::ok()returns false.We're currently finishing loggers at shutdown (see here), and I think that part of the idea is to stop doing that and doing it when the context is destructed.
If we do that change,
initshould make sure to handle the problem correctly (it's possible with some extra lines here).We could also provide a
reinitmethod that takes no arguments. It will make sure that the context is valid again, and it uses the same init options passed before (i.e. it only switches a flag).examples:
We should make sure both examples above work.
If the user is trying to call
rclcpp::Context::initfrom more than one thread, it will be a problem.But I don't think we should provide such thread safety guarantee.
wjwwood commentedon Jul 1, 2020
It's not though... It's only safe to do that after the context is destructed right?
I haven't tried it recently, but you should be able to init/shutdown contexts in parallel as long as you're using different ones each time. Maybe the global logging setup doesn't make that work anymore.
ivanpauno commentedon Jul 1, 2020
I think it's currently safe, as
shutdownis finishing the logger and init will be able to setup it again correctly (supposing only one context).If we move logging finishing to context destruction, we will need to handle that case in
init.It should work if one context initializes the logging system and the other doesn't.
I think it would be great to move the global context configuration to one per Context, but that doesn't seem to be exactly related (I will create an issue and add it to the Galactic project board).
I think we should add test for all these cases when doing the change, so it will be clear what works and what doesn't.
Both cases can conceptually work correctly with the change in shutdown behavior.
jacobperron commentedon Jul 10, 2020
Although not required, it would be nice if the solution to this issue (or version of it) could be backported to Foxy.
hidmic commentedon Jul 20, 2020
A few comments here and there:
I see. It's a valid point. Perhaps spinning a entity associated with a shutdown context shouldn't throw an exception?
I guess the question is, what's the point of having a third shutdown state besides the usual init-fini cycle? If we only intend it to be a generic notification with no side-effects of its own, why making it a separate state? Why restricting it to a single event? Why do we call it
shutdown?As I see it, to shutdown means a context and all entities associated with it are soon to be finalized. That certainly bans entity creation and restricts the amount of work you can do (spinning is a good example of what should be allowed, or otherwise the added state is somewhat useless). And while we don't do anything meaningful about it right now, if anyone ever wants to:
rmwuses)we'll need the concept.
I will say that's because
rclcpp::Context::initsilently destroys the underlyingrclcontext. Belowrclcpp, it's init-shutdown-fini and only then a context can be reused.This is true because
rcluses an atomic flag to invalidate contexts, instead of relying onrmwwhich also has to track shutdown contexts (to comply withrmw_context_fini()API). Finalized and shutdown context states could be perfectly distinguishable.wjwwood commentedon Jul 20, 2020
That's what I imagined as well, but I think there's a need for another use case too, but whether or not that should be part of the same mechanism, I'm not sure. For example, we need a "you should stop, cleanup, and exit your node's main functions". That's what
shutdown()meant in ROS 1 for the most part.hidmic commentedon Jul 21, 2020
Yeah, I see it. I'm just not convinced that's
Context::shutdown()purpose. And for the record, I'm not advocating for having both if we don't think it's worth the effort. Perhaps what we're looking for is someContext::interrupt()primitive?ivanpauno commentedon Jul 21, 2020
In ROS 1, calling shutdown from a different thread was safe.
A lots of the functions were a noop after shutdown happen, and didn't raise an exception.
e.g:
spinafter shutdown, it returned immediately.Based on that, I think that the current ROS 2 shutdown behavior isn't quite the same.
Sure, but that doesn't mean that shutdown should destroy things or make things raise an unknown exception IMO.
IMHO, it's not a good idea to add a different method that it's similar and doesn't do exactly the same that shutdown (except if we have a strong use case for that).
The problem is that
shutdownisn't thread safe, and it was thread safe in ROS 1.I think that we should fix that first. We can add a different mechanism later if we find the need.
hidmic commentedon Jul 21, 2020
Agree about not destroying things, and raising unknown exceptions is never an option. But that happens because we don't deal with shutdowns properly yet.
I can't argue about the need for use cases. And I agree that it should be made thread-safe. What I'm calling out, based on the preceding discussion, is the attempt to turn
shutdowninto something conceptually different in the process. If the plan to make it thread-safe is to make it a flag and leave side-effects to calling code, that's fair, but don't call itshutdown(just likeKeyboardInterruptisn'tShutdownRequesteven though that's the typical use case). I don't even see the need for a separate context state really if that's all we want from it.ivanpauno commentedon Jul 21, 2020
What does "dealing with shutdowns properly" mean?
I think that's the main question here, and I'm failing to get a consensus of what it means.
AFAIS, in ROS 1 it was actually a flag.
After that flag was
true, some things start behaving as a noop but never retrieved an error.I'm not sure what "separate context state" is referring to.
I would say that a
KeyboardInterruptcan be considered aShutdownRequest, but not the opposite way around.We will probably need to set up a meeting to discuss this, as this discussion is getting quite long.
hidmic commentedon Jul 21, 2020
Agreed.
But to entertain the discussion:
IMHO to have APIs behave in a well-defined, thread-safe, and documented way when a shutdown occurs (no random exception, no UB, etc.).
I'm not onboard with how ROS 1 did lots of things. Whether ROS 2 should mimic for the sake of familiarity or depart in an attempt to improve is a somewhat philosophical discussion.
To have an invalidated context as a notification, instead of simply sending a notification.
wjwwood commentedon Sep 22, 2020
We should definitely have some meetings to nail this down.
With respect to the topic of emulating ROS 1 or not in this case, I think we shouldn't. This is mostly based on my experience with clients like Apex, where consistent behavior is key, and having a variety of reactions from the API when shutdown is called makes it hard to know (without 100% familiarity with the entire API) what will happen.
To that end, I think the best idea is just making shutdown a flag, and have none of our API change its behavior when that occurs, instead, allowing the user to decide how to detect/check for it and handle it.
If there is then cases which are common place and are becoming boilerplate, we can add convenience to reduce code duplication, but should ideally be opt-in so the default behavior is predictable and unsurprising, even if they're a bit inconvenient.
This is just all my opinion at this point, and I definitely not sure it's the correct path, but we should discuss it and come to some consensus. 👍