ros2 / rclpy

rclpy (ROS Client Library for Python)
Apache License 2.0
299 stars 224 forks source link

ActionClient and ActionServer crash on destruction #524

Open rotu opened 4 years ago

rotu commented 4 years ago

Bug report

Required Info:

Steps to reproduce issue

colcon test --packages-select test-communication

Expected behavior

Destroying the action client should happen gracefully.

Actual behavior

An error is thrown when the action client or the action server is garbage collected:

http://build.ros2.org/view/Fci/job/Fci__nightly-cyclonedds_ubuntu_focal_amd64/lastBuild/consoleText

17: Starting test run test_communication.test_action_client_server__rclpy__rmw_fastrtps_cpp_.launch_tests[Fibonacci]
17: [INFO] [launch]: All log files can be found below /home/buildfarm/.ros/log/2020-03-12-04-03-39-582329-e523ecceac2a-5255
17: [INFO] [launch]: Default logging verbosity is set to INFO
17: test_client_finishes_in_a_finite_amount_of_time[Fibonacci] (test_communication.TestActionClientServer)
17: Test that the second executable terminates after a finite amount of time. ... [INFO] [test_action_server-1]: process started with pid [5258]
17: [INFO] [test_action_client-2]: process started with pid [5260]
17: [test_action_client-2] Sending goal for test number 0
17: [test_action_client-2] Exception ignored in: <function ActionClient.__del__ at 0x7f2115f12700>
17: [test_action_client-2] Traceback (most recent call last):
17: [test_action_client-2]   File "/tmp/ws/install_isolated/rclpy/lib/python3.8/site-packages/rclpy/action/client.py", line 596, in __del__
17: [test_action_client-2]   File "/tmp/ws/install_isolated/rclpy/lib/python3.8/site-packages/rclpy/action/client.py", line 589, in destroy
17: [test_action_client-2]   File "/tmp/ws/install_isolated/rclpy/lib/python3.8/site-packages/rclpy/handle.py", line 124, in __enter__
17: [test_action_client-2]   File "/tmp/ws/install_isolated/rclpy/lib/python3.8/site-packages/rclpy/handle.py", line 106, in _get_capsule
17: [test_action_client-2] rclpy.handle.InvalidHandle: Tried to use a handle that has been destroyed.
17: [INFO] [test_action_client-2]: process has finished cleanly [pid 5260]
17: ok
17: 
17: ----------------------------------------------------------------------
17: Ran 1 test in 1.187s
17: 
17: OK
17: [INFO] [test_action_server-1]: sending signal 'SIGINT' to process[test_action_server-1]
17: [test_action_server-1] Exception ignored in: <function ActionServer.__del__ at 0x7fce84bc3040>
17: [test_action_server-1] Traceback (most recent call last):
17: [test_action_server-1]   File "/tmp/ws/install_isolated/rclpy/lib/python3.8/site-packages/rclpy/action/server.py", line 625, in __del__
17: [test_action_server-1]   File "/tmp/ws/install_isolated/rclpy/lib/python3.8/site-packages/rclpy/action/server.py", line 618, in destroy
17: [test_action_server-1]   File "/tmp/ws/install_isolated/rclpy/lib/python3.8/site-packages/rclpy/handle.py", line 124, in __enter__
17: [test_action_server-1]   File "/tmp/ws/install_isolated/rclpy/lib/python3.8/site-packages/rclpy/handle.py", line 106, in _get_capsule
17: [test_action_server-1] rclpy.handle.InvalidHandle: Tried to use a handle that has been destroyed.
17: [INFO] [test_action_server-1]: process has finished cleanly [pid 5258]
17: test_processes_finished_gracefully[Fibonacci] (test_communication.TestActionClientServerAfterShutdown)
17: Test that both executables finished gracefully. ... ok
17: 

Additional information

We should probably not be using __del__ at all, since it executes when the object is garbage-collected, which happens at an indeterminate time. It should probably instead be cleaned up when the parent node terminates.

MatteoRagni commented 4 years ago

We are experiencing similar problems with Opensplice DDS, on Ubuntu 18.04.

We are experiencing segmentation fault when we try to destroy the server or the client. We tried a post mortem debug of the core dumped, but we have a very short bt with no useful information inside.

If we destroy an ActionServer explicitly, we see a segmenetation fault. If we leave it and let the node and rclpy to destroy it at shutdown there is no error.

karl-schulz commented 2 years ago

Is there any progress on this? We are experiencing the same issue and it is quite misleading for people not knowing about it, thinking they did something wrong.

In comparison, service clients and servers are destroyed on a node's destroy_node() call, avoiding this issue.