ros-tooling / topic_tools

Tools for directing, throttling, selecting, and otherwise manipulating ROS 2 topics at a meta-level.
Apache License 2.0
71 stars 33 forks source link

`KeyboardInterrupt` exception on shutdown #104

Open Timple opened 5 months ago

Timple commented 5 months ago

Description

KeyboardInterrupt exception on shutdown

Expected Behavior

Clean shutdown

Actual Behavior

[relay_field-69] Traceback (most recent call last):
[relay_field-69]   File "/opt/ros/iron/lib/topic_tools/relay_field", line 33, in <module>
[relay_field-69]     sys.exit(load_entry_point('topic-tools==1.2.0', 'console_scripts', 'relay_field')())
[relay_field-69]   File "/opt/ros/iron/lib/python3.10/site-packages/topic_tools/relay_field.py", line 226, in main
[relay_field-69]     node.destroy_node()
[relay_field-69]   File "/opt/ros/iron/lib/python3.10/site-packages/rclpy/node.py", line 1887, in destroy_node
[relay_field-69]     self.__node.destroy_when_not_in_use()
[relay_field-69] KeyboardInterrupt

To Reproduce

** Steps to reproduce the behavior, e.g.

  1. ros2 topic pub /chatter std_msgs/String "{}"
  2. ros2 run topic_tools relay_field /chatter /chatter2 std_msgs/String "{data: m.data}"
  3. Press ctrl+C
  4. Watch error

System (please complete the following information)

MichaelOrlov commented 3 months ago

Preliminary analysis

The failure is very strange. It turns out that we already have KeyboardInterrupt handler in the relevant relay_field.py https://github.com/ros-tooling/topic_tools/blob/cefac4787f10a706d4bacf115c628b95f5033461/topic_tools/topic_tools/relay_field.py#L217-L227

Also according to the call stack, the failure happened inside node.destroy_node() call on the self.__node.destroy_when_not_in_use().

It might be that SIGINT arrived twice. i.e., the second time when we were already in the final stage in the self.__node.destroy_when_not_in_use(). Need to reproduce and debug this issue.