-
-
Notifications
You must be signed in to change notification settings - Fork 681
SIGINT and SIGTERM Handling #75
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
Comments
How do you handle the case where multiple child-processes are run concurrently through |
@smyrman That is an interesting question. I have not thought about this deeply nor have I had the need to deal with parallel termination. Assuming that the parallel processes are not dependent on each other (i.e. they are not doing some sort of IPC or being run as daemons of sorts for use by other processes in the parallel stack) it might be reasonable to do the following:
This is where some choices have to be made4a. Be like go, Exit with 1. When go traps either SIGINT or SIGTERM it's exit code will always be 1 to indicate abnormal termination. IMHO 4b is probably the right choice. |
I don't suppose you would be interesting in trying a PR? There might be need for some clean-up of the code to get to the stage where it's easy to add. This is a good file to start looking at: https://github.com/go-task/task/blob/master/task.go |
/cc @mvdan Sorry for pinging you again. Do you have any idea if it's possible to send a SIGINT to a process run by the interp? Today Task only cancels the context and forget about it. I think this will just kill the process. |
I haven't thought about signals at all, and nothing is done about them at the moment. But I knew it would become an issue at some point. At the moment, If it is possible in a simple program, it is also likely possible in |
Thanks @mvdan Seems that the context cancelation calls os.Process.Kill which kills the process. There's os.Process.Signal. I think it's possible to hook the Context to call that instead of passing the context to |
I don't know if it's worth the complexity, or if it's a good fit for the rest of the code base, but if you think global exit handler would be the right abstraction, you may look at: |
@andreynering if you would like to give that a try and submit a patch, I'd be happy to review. It would be best for the solution to not be global, although I'm not sure if that is possible given that signals are per-process and not per-goroutine. |
Now merged - thanks! Will release 2.1 soon, but you can vendor an updated master as you've been doing. |
@pmorton Let us know if the recent changes improved this use case for you. |
Hi - I recently discovered go-task. Overall this is pretty impressive! I am utilizing go-task as a makefile replacement on a repository that builds packer (another great go project) images. In the process I have discovered that go-task does not proxy unix signals to child processes. This presents an issue when the task that go-task is running needs to do clean up. For example, when the packer process receives SIGINT (ctrl+c) it will stop what is it doing and execute its cleanup actions so as not to leave random artifacts of half build VMs. Having go-task handle signals in the following way would help to address this issue:
As a bonus, if go-task receives SIGINT or SIGTERM more than once, it should exit immediately.
The text was updated successfully, but these errors were encountered: