Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

joy_linux: clean shutdown when terminated by signal handler #293

Open
wants to merge 1 commit into
base: ros2
Choose a base branch
from

Conversation

oysstu
Copy link

@oysstu oysstu commented Dec 10, 2024

The joy_linux node does not shut down gracefully if terminated by a signal, for example CTRL+C/SIGINT. This happens because the context is invalidated by the signal handler, and the node main function attempts to call spin_node directly after exiting the innermost while loop. Example of unclean exit:

[INFO] [1733839990.289835426] [joy_node]: Opened joystick: /dev/input/js0. deadzone_: 0.050000.
^C[INFO] [1733839993.157844512] [rclcpp]: signal_handler(signum=2)
terminate called after throwing an instance of 'rclcpp::exceptions::RCLError'
  what():  failed to create guard condition: the given context is not valid, either rcl_init() was not called or rcl_shutdown() was called., at /tmp/makepkg/ros2-jazzy-base/src/ros2/src/ros2/rcl/rcl/src/rcl/guard_condition.c:67
Aborted (core dumped)

This PR moves the offending call to spin_some inside the rclcpp::ok() check to at least catch most of these cases. This results in a clean shutdown without the exception:

[INFO] [1733841481.096457734] [joy_node]: Opened joystick: /dev/input/js0. deadzone_: 0.050000.
^C[INFO] [1733841482.468186414] [rclcpp]: signal_handler(signum=2)
[INFO] [1733841482.573050534] [joy_node]: joy_node shut down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant