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
Intra-process Type adaptation failing silently if types mismatch #2291
Intra-process communication is currently supported together with type adaptation, and works fine as long as both the publisher and the subscriber both use a ROS-msg type or the same custom-type. However, if the publisher uses a custom-type and the subscriber a ROS-msg type, the communication (as can be expected) fails if the intra-process communication is enabled.
When this kind of failure occurs, no warning / error / exception is reported, resulting in a silent failure which is potentially difficult to debug. I'm not sure if implementing this kind of check would be complicated, but I think it would make using type-adaptation less error-prone.
Warnings, errors, exceptions, or ros2 doctor logs are reported when the types used by the publisher and the subscriber are not matching and the intra-process communication is enabled.
Actual behavior
The communication fails (no message is received by the subscriber) silently.
However, if the publisher uses a custom-type and the subscriber a ROS-msg type, the communication (as can be expected) fails if the intra-process communication is enabled.
Where you found evidence / documentation? If intra-process is enabled the adapter is not able to do conversion from/to message?
Hi @roncapat , I found no documentation in this regard, but I verified it through tests (see the linked repo). It is also intuitive that, if a conversion needes to be applied, it is not possible to efficiently share a pointer between publisher and subscriber. However, I think some sort of warning or a fallback to the normal communication mechanism would be desirable in this scenario.
I imagine this could accidentally happen if the subscriber doesn't know which mechanism is being used by the publisher (for example if the programmer misses access to the pub source code). Yet this wouldn't really be a "use-case", since the subscriber can always disable the intra-process option in this scenario, so I suppose an exception would be fine.
I have a library of components that use my private message adapters. If I want to compose them with 3rd party packages with intra-process on (because I need it for some topics that exchange data with other components of mine) I can't make the mix work (I may have to enable/disable intra process per-topic via param file). So yes, now that I recall, I already experienced this issue in the past.
The case of an intraprocess pub/sub, with one side being a ROSMsg and the other side being Custom, should be supported for the reasons @roncapat points out. It obviously involves a copy, so isn't as efficient as a ROSMsg<->ROSMsg or Custom<->Custom, but it should still work.
It's been a couple of years since I looked at this, but I believe we even tested that at the time we added in type adaptation. My opinion is that this should be treated as a bug and fixed.
Good point; I wasn't thinking of "composition" involving third-party code (that you may or may not have control over its source).
We should still add a warning when the pub and sub discover each others (even if there's a valid use-case for it, notifying the users via a log will help them identify possible undesired inefficiencies in their pipeline).
Thanks a lot @iuhilnehc-ynos, I can confirm that applying the patch on top of rclcpp 21.0.2 solved the problem, at least for this specific test.
[component_container-1] [INFO] [1693472229.766338070] [adapted_publisher]: Publishing to ADAPTED topic cloud with address: 0x5581E17A9020
[component_container-1] [INFO] [1693472229.766626558] [adapted_publisher]: Publishing to NOT ADAPTED topic cloud with address: 0x5581E159DC20
[component_container-1] [INFO] [1693472229.767263217] [adapted_subscriber]: Adapted sub received cloud with address: 0x5581E17A9020
[component_container-1] [INFO] [1693472229.767467450] [adapted_subscriber]: Normal sub received cloud with address: 0x5581E1AA1740
Activity
roncapat commentedon Aug 30, 2023
Hi @nirwester, may I ask you about this:
Where you found evidence / documentation? If intra-process is enabled the adapter is not able to do conversion from/to message?
nirwester commentedon Aug 30, 2023
Hi @roncapat , I found no documentation in this regard, but I verified it through tests (see the linked repo). It is also intuitive that, if a conversion needes to be applied, it is not possible to efficiently share a pointer between publisher and subscriber. However, I think some sort of warning or a fallback to the normal communication mechanism would be desirable in this scenario.
roncapat commentedon Aug 30, 2023
Exactly, I just thought a fallback would happen in that case... that's why now I'm interested in this thread :)
alsora commentedon Aug 30, 2023
Are there use-cases to have a publisher and a subscriber in the same process where one uses a ROS-msg type and the other uses a custom type?
I can't think of any valid use-case, so I would throw an exception rather than a warning.
MarcoMatteoBassa commentedon Aug 30, 2023
I imagine this could accidentally happen if the subscriber doesn't know which mechanism is being used by the publisher (for example if the programmer misses access to the pub source code). Yet this wouldn't really be a "use-case", since the subscriber can always disable the intra-process option in this scenario, so I suppose an exception would be fine.
roncapat commentedon Aug 30, 2023
I have a library of components that use my private message adapters. If I want to compose them with 3rd party packages with intra-process on (because I need it for some topics that exchange data with other components of mine) I can't make the mix work (I may have to enable/disable intra process per-topic via param file). So yes, now that I recall, I already experienced this issue in the past.
clalancette commentedon Aug 30, 2023
The case of an intraprocess pub/sub, with one side being a ROSMsg and the other side being Custom, should be supported for the reasons @roncapat points out. It obviously involves a copy, so isn't as efficient as a ROSMsg<->ROSMsg or Custom<->Custom, but it should still work.
It's been a couple of years since I looked at this, but I believe we even tested that at the time we added in type adaptation. My opinion is that this should be treated as a bug and fixed.
alsora commentedon Aug 30, 2023
Good point; I wasn't thinking of "composition" involving third-party code (that you may or may not have control over its source).
We should still add a warning when the pub and sub discover each others (even if there's a valid use-case for it, notifying the users via a log will help them identify possible undesired inefficiencies in their pipeline).
iuhilnehc-ynos commentedon Aug 31, 2023
Let me share my two cents.
The
rclcpp/rclcpp/include/rclcpp/experimental/intra_process_manager.hpp
Line 489 in 43cf0be
rclcpp/rclcpp/include/rclcpp/type_adapter.hpp
Lines 97 to 100 in 43cf0be
I think something below might be correct.
MarcoMatteoBassa commentedon Aug 31, 2023
Thanks a lot @iuhilnehc-ynos, I can confirm that applying the patch on top of rclcpp 21.0.2 solved the problem, at least for this specific test.
roncapat commentedon Aug 31, 2023
Nice!
Next steps? PR with some warnings added?
clalancette commentedon Aug 31, 2023
I'd say let's make a PR with that change and a new test. Adding a warning I think should be done in a separate PR, so we can discuss it separately.
roncapat commentedon Aug 31, 2023
@iuhilnehc-ynos as the patch is yours, would you like to open the PR?
fujitatomoya commentedon Aug 31, 2023
@iuhilnehc-ynos please take care of opening the PR, i am happy to do review.
fujitatomoya commentedon Sep 16, 2023
Just FYI, backport to iron and humble are completed.
nirwester commentedon Sep 16, 2023
Thanks a lot @fujitatomoya and everybody!