-
Notifications
You must be signed in to change notification settings - Fork 162
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
Signal propagation by the ros2 run verb #895
Comments
Yeah, I'm guessing this is the reason for the difference in behavior. Windows does not have |
i am not sure what you are expecting here. > docker run --rm -d osrf/ros:humble-desktop ros2 run demo_nodes_cpp talker
aeceb9dc2f4cee7d1ddebbb1d2241c3602a662e699d43a20d481bcfecd2ac51f
> ps -ef | grep humble
root 3516555 3516533 1 16:03 ? 00:00:00 /usr/bin/python3 /opt/ros/humble/bin/ros2 run demo_nodes_cpp talker
root 3516613 3516555 0 16:03 ? 00:00:00 /opt/ros/humble/lib/demo_nodes_cpp/talker
tomoyaf+ 3516708 7546 0 16:03 pts/0 00:00:00 grep --color humble
> docker stop aeceb9dc2f4c
aeceb9dc2f4c
> ps -ef | grep humble
tomoyaf+ 3517055 7546 0 16:04 pts/0 00:00:00 grep --color humble |
How about adding the signal handler in |
Yes, the
Exactly, that is also what I meant by the first item in the "Feature Request" section of the issue description. But implementation-wise it would be simpler to replace the |
@meyerj thanks for providing the good information. i think i can come up with patch fix for this. (in addition to the patch fix, we should probably add this information how to use docker container in ros2 documentation somewhere in https://docs.ros.org/en/rolling/How-To-Guides/Run-2-nodes-in-single-or-separate-docker-containers.html)
besides this, we will lose writer cache data... this is bad... |
I am not sure whether exec ros2 bag record ... with some predefined and commonly used options specific to the application, like we sometimes do at Intermodalics. Note that if you would forget the Thanks for the quick solution, code-wise it looks good and should resolve the issue! I quickly built the patched version in an overlay workspace with ROS 2 Humble binaries installed from http://packages.ros.org/ros2/ubuntu, and the example snippet from the description behaves as expected now. |
Ah sorry, my bad... you are correct. my PR just fixes it does not fork the process, besides it handles signals https://github.com/ros2/rosbag2/blob/a111ee561fb8cb54a56ae91eb5b29a7e347967f2/rosbag2_py/src/rosbag2_py/_transport.cpp#L175-L180
appreciate that! |
Since we already have |
Bug report
Required Info:
Steps to reproduce issue
Expected behavior
The
talker
process should cleanly terminate, as if the signal was sent directly to the child process. Some processes may have to perform some cleanup work, like close files, log something etc.If I do not use
ros2 run
and launch the node executable directly, everything does work as expected:With this variant, the
talker
process terminates cleanly, thenwait
returns.The shell script is only an exemplary example - there are other cases where a supervisor process monitors its children and expects them to terminate after sending a TERM signal, e.g. systemd or the Docker daemon. Other signals should also be propagated and may be needed by some processes, for example
SIGPIPE
orSIGWINCH
or user signalsSIGUSR1
andSIGUSR1
.Actual behavior
The SIGTERM signal is handled by the
ros2 run
Python process in the default way, and it terminates and detaches from its childtalker
, but the signal is not propagated and the node keeps running and talking. I did not expect thatros2 run
does not replace itself by the launched process, likerosrun
in ROS 1 did, apparently only for the sake of logging when the child process terminated and its exit status.It would be possible to work around by sending the signal to all child processes of $PID (e.g.
pkill -P $PID
), or other techniques to send the signal to the actual process instead of the direct child process. Or use ROS 2 launch.Pressing Ctrl-C in the same terminal before
ros2 run
process was terminated works, because the shell sends theSIGINT
signal to all processes in its process group then, including thetalker
. After thetalker
was detached and the script finished, Ctrl-C has no effect anymore on the running node process.A similar (undesired) effect when running in Docker:
While this works fine and
docker stop
returns after 1-2 seconds:Feature request
Feature description
ros2 run
should propagate all signals that can be handled to its child process, or at least SIGINT and SIGTERM.os.execve()
and its variants, to replace the current process by the child process, likerosrun
in ROS 1 did.ros2 run
process should never terminate and leave its child running detached.Implementation considerations
I am not sure how other platforms, like Windows, are dealing with this and whether replacing the process with its child would work there.
The text was updated successfully, but these errors were encountered: