ros2-for-unity: Calling Dispose() on Subscriber raises an Exception after few calls

This issue #21 was fixed previously so that calling Dispose does not cause immediate crash. But same error still occurs if topics are subscribed/disposed in fast manner. I attached a C++ test program that publishes several topics and also publishes add/remove commands to tell what topics should be subscribed/disposed. Also attached a sample Unity code that receives those topics and subscribes/disposes topics according to received messages. This code causes the error RuntimeError: subscription's implementation is invalid, at /tmp/binarydeb/ros-foxy-rcl-1.1.11/src/rcl/subscription.c:462, at /tmp/binarydeb/ros-foxy-rcl-1.1.11/src/rcl/wait.c:324 to happen in few seconds.

dispose.zip

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 26 (8 by maintainers)

Most upvoted comments

The patch has now been in test run in four setups and we have not seen any exceptions. This really seems to fix the problem. Good job! The problem of Dispose not actually removing subscriptions still persists but that is another problem, I will continue to investigate it and create new issue when I can reproduce it.

Every time a new subscription is created, old one is first disposed and then set to null. So, no, I do not think that the scenario happens. We have no threads of our own. The ROS2 callbacks are called with separate threads so data is protected by locks or ConcurrentQueue is used to pass messages to Unity thread.

I looked on ros2 sources about this exception. The wait.c:324 is in function rcl_wait_set_add_subscription. This is strange since the error happens always on disposing the subscription, not when adding new subscription. Last time I saw this, several minutes were passed from last added subscription. Then there was six removal of subscriptions, last one caused the exception.