-
Notifications
You must be signed in to change notification settings - Fork 256
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 can't be caught by the underlying binary #269
Comments
Yeah, thanks for bringing this up, that's something we should make work correctly - passing a signal down from mage to the commands you're executing. It will take some work, but I think it's doable. |
Thanks for the quick response. |
Just wanted to check if anyone is working on this before opening a PR. |
I don't believe the linked PR addresses this issue. If I'm reading this right, it will issue a if err := cmd.Start(); err != nil {
log.Fatal(err) // Command not found on PATH, not executable, &c.
}
// wait for the command to finish
waitCh := make(chan error, 1)
go func() {
waitCh <- cmd.Wait()
close(waitCh)
}()
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan)
// You need a for loop to handle multiple signals
for {
select {
case sig := <-sigChan:
if err := cmd.Process.Signal(sig); err != nil {
// Not clear how we can hit this, but probably not
// worth terminating the child.
log.Print("error sending signal", sig, err)
}
case err := <-waitCh:
// Subprocess exited. Get the return code, if we can
var waitStatus syscall.WaitStatus
if exitError, ok := err.(*exec.ExitError); ok {
waitStatus = exitError.Sys().(syscall.WaitStatus)
os.Exit(waitStatus.ExitStatus())
}
if err != nil {
log.Fatal(err)
}
return
}
} |
Hi @flowchartsman, My PR will allow the magefile to catch a sigint, this is covered with this test, sigkill is issued after a second sigint is received. |
@pmcatominey Thanks for working on this. I am new to Mage and was wondering if this could help with having My use case is having a Go project consisting of multiple micro-services in |
Hi everyone
Moved my code from makefile to mage and I'm very pleased so thank you for the great work!
I'm running another go binary which has a loop running and this code to catch signals
then this code a bit later:
but when i ctrl + c my mage running process the underlying process doesn't receive any signal.
I've seen it with other executables that do cleanup on terminal as well such as terraform.
Let me know if you have any idea on how to approach a fix here or maybe if I'm missing something.
Thanks!
The text was updated successfully, but these errors were encountered: