Cntl-c/killall gives rcl_shutdown already called only Humble/Jammy
I have written a basic IMU publisher node (that does not implement lifecycle) which is throwing a "rcl_shutdown already called" error in ROS2 Humble on Jammy (Ubuntu 22.04 Server on Raspberry Pi4) when killed.
It quits cleanly under ROS2 Foxy on Focal (Ubuntu 20.04 Server on Raspberry Pi4).
printenv | grep ROS
ROS_VERSION=2
ROS_PYTHON_VERSION=3
ROS_DOMAIN_ID=0
ROS_LOCALHOST_ONLY=0
ROS_DISTRO=humble
uname -a
Linux ROS2HH 5.15.0-1017-raspi #19-Ubuntu SMP PREEMPT Fri Oct 14 08:22:47 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
Started in foreground and terminated with cntrl-c:
ros2 run ros2_gopigo3_node imu_sensor
Started in background and terminated with killall:
ros2 run ros2_gopigo3_node imu_sensor &
killall imu_sensor
My node:
#!/usr/bin/env python3
# File: imu_sensor.py
# Basic ROS2 Node to publish imu sensor readings
"""
Publishes:
/imu/data
/imu/mag in units of full Tesla 1 microTesla = 0.000001 Tesla
/imu/temp
TODO:
/imu/status
/imu/raw
"""
class IMUSensorNode(Node):
def __init__(self):
super().__init__('imu_sensor')
...
def timer_callback(self):
...
def main(args=None):
rclpy.init(args=args)
imu_node = IMUSensorNode()
try:
rclpy.spin(imu_node)
except KeyboardInterrupt:
print('\ncontrol-c: imu_sensor node shutting down')
finally:
imu_node.destroy_node()
rclpy.shutdown()
Note: it throws the same error on exit without the try-except-finally construct also:
def main(args=None):
rclpy.init(args=args)
imu_node = IMUSensorNode()
rclpy.spin(imu_node)
imu_node.destroy_node()
rclpy.shutdown()
This is the full error:
$ ros2 run ros2_gopigo3_node imu_sensor
[INFO] [1666452685.296127347] [imu_sensor]: Created imu_sensor node at 30 hz
^C
control-c: imu_sensor node shutting down
Traceback (most recent call last):
File "/home/ubuntu/ros2ws/install/ros2_gopigo3_node/lib/ros2_gopigo3_node/imu_sensor", line 33, in <module>
sys.exit(load_entry_point('ros2-gopigo3-node==0.0.0', 'console_scripts', 'imu_sensor')())
File "/home/ubuntu/ros2ws/install/ros2_gopigo3_node/lib/python3.10/site-packages/ros2_gopigo3_node/imu_sensor.py", line 121, in main
rclpy.shutdown()
File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/__init__.py", line 126, in shutdown
_shutdown(context=context)
File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/utilities.py", line 58, in shutdown
return context.shutdown()
File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/context.py", line 102, in shutdown
self.__context.shutdown()
rclpy._rclpy_pybind11.RCLError: failed to shutdown: rcl_shutdown already called on the given context, at ./src/rcl/init.c:241
[ros2run]: Process exited with failure 1