Skip to content

Commit 5494240

Browse files
committed
gps: kill entire child process group on failure
Previously, if dep tried to clone a repository over ssh that contained zero padded file modes, dep would fail to clone and then hang. You can reproduce this failure with the following .gitconfig: [url "[email protected]:"] insteadOf = https://github.com/ [transfer] fsckobjects = true [fetch] fsckobjects = true [receive] fsckobjects = true and the following Gopkg.toml. (It is not my intention to single out this project - I searched Github for Go projects with zero padded file mode errors, and found this one.) [[constraint]] name = "github.com/remogatto/gospeccy" branch = "master" `dep ensure` hangs because the git clone operation spins up an `ssh` process as a child process. `cmd.Process.Kill` kills the parent `git` operation, but not the child `ssh` operation, so it's orphaned and we don't return properly from the function. (It's unclear to me at this point why the ssh operation did not return when it completed.) By sending the negative Pgrp value to the Kill() function we can kill the entire child process group, not just the "parent child." See https://medium.com/@felixge/killing-a-child-process-and-all-of-its-children-in-go-54079af94773 for more information. Updates golang#1257.
1 parent d3c1e41 commit 5494240

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Gopkg.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gps/cmd_unix.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"time"
1616

1717
"github.com/pkg/errors"
18+
"golang.org/x/sys/unix"
1819
)
1920

2021
type cmd struct {
@@ -66,10 +67,10 @@ func (c cmd) CombinedOutput() ([]byte, error) {
6667
if err := c.Cmd.Process.Signal(os.Interrupt); err != nil {
6768
// If an error comes back from attempting to signal, proceed
6869
// immediately to hard kill.
69-
_ = c.Cmd.Process.Kill()
70+
_ = unix.Kill(-c.Cmd.Process.Pid, syscall.SIGKILL)
7071
} else {
7172
defer time.AfterFunc(time.Minute, func() {
72-
_ = c.Cmd.Process.Kill()
73+
_ = unix.Kill(-c.Cmd.Process.Pid, syscall.SIGKILL)
7374
}).Stop()
7475
<-waitDone
7576
}

0 commit comments

Comments
 (0)