From bea24e2592ec3178c63464a8b7a9dafa8f7c03a0 Mon Sep 17 00:00:00 2001 From: sam boyer Date: Thu, 12 Oct 2017 22:38:58 -0400 Subject: [PATCH 1/4] gps: Break ctx chain so that Kill isn't autofired --- internal/gps/cmd_unix.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/gps/cmd_unix.go b/internal/gps/cmd_unix.go index f5a5f4156b..e8f741aaba 100644 --- a/internal/gps/cmd_unix.go +++ b/internal/gps/cmd_unix.go @@ -25,11 +25,15 @@ type cmd struct { } func commandContext(ctx context.Context, name string, arg ...string) cmd { - // Grab the caller's context and pass a derived one to CommandContext. - c := cmd{ctx: ctx} - ctx, cancel := context.WithCancel(ctx) - c.Cmd = exec.CommandContext(ctx, name, arg...) - c.cancel = cancel + // Create a one-off cancellable context for use by the CommandContext, in + // the event that we have to force a Process.Kill(). + ctx2, cancel := context.WithCancel(context.Background()) + + c := cmd{ + Cmd: exec.CommandContext(ctx2, name, arg...), + cancel: cancel, + ctx: ctx, + } return c } From 6bbd19d9082525c620b05808d7690d78aeee0411 Mon Sep 17 00:00:00 2001 From: sam boyer Date: Thu, 12 Oct 2017 22:40:53 -0400 Subject: [PATCH 2/4] gps: Force subprocesses into new pgroup on unix This puts us more squarely in control of subprocess signaling. --- internal/gps/cmd_unix.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/gps/cmd_unix.go b/internal/gps/cmd_unix.go index e8f741aaba..47753e417e 100644 --- a/internal/gps/cmd_unix.go +++ b/internal/gps/cmd_unix.go @@ -11,6 +11,7 @@ import ( "context" "os" "os/exec" + "syscall" "time" "github.com/pkg/errors" @@ -51,6 +52,17 @@ func (c cmd) CombinedOutput() ([]byte, error) { var b bytes.Buffer c.Cmd.Stdout = &b c.Cmd.Stderr = &b + + // Force subprocesses into their own process group, rather than being in the + // same process group as the dep process. Ctrl-C sent from a terminal will + // send the signal to the entire running process group, so This allows us to + // directly manage the issuance of signals to subprocesses in that common + // case. + c.Cmd.SysProcAttr = &syscall.SysProcAttr{ + Setpgid: true, + Pgid: 0, + } + if err := c.Cmd.Start(); err != nil { return nil, err } From 8de86c40c3131e7685ca56aa604a85c39ac5e22b Mon Sep 17 00:00:00 2001 From: sam boyer Date: Thu, 12 Oct 2017 22:41:27 -0400 Subject: [PATCH 3/4] gps: Strings for calltypes --- internal/gps/source_manager.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/internal/gps/source_manager.go b/internal/gps/source_manager.go index 23f3c1c8b5..926c623231 100644 --- a/internal/gps/source_manager.go +++ b/internal/gps/source_manager.go @@ -741,6 +741,29 @@ const ( ctExportTree ) +func (ct callType) String() string { + switch ct { + case ctHTTPMetadata: + return "Retrieving go get metadata" + case ctListVersions: + return "Retrieving latest version list" + case ctGetManifestAndLock: + return "Reading manifest and lock data" + case ctListPackages: + return "Parsing PackageTree" + case ctSourcePing: + return "Checking for upstream existence" + case ctSourceInit: + return "Initializing local source cache" + case ctSourceFetch: + return "Fetching latest data into local source cache" + case ctExportTree: + return "Writing code tree out to disk" + default: + panic("unknown calltype") + } +} + // callInfo provides metadata about an ongoing call. type callInfo struct { name string From 239acdaedc7d2ad555fe911c18cb465e89ad6834 Mon Sep 17 00:00:00 2001 From: sam boyer Date: Fri, 13 Oct 2017 10:44:45 -0400 Subject: [PATCH 4/4] gps: Set pgroup controls in cmd constructor --- internal/gps/cmd_unix.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/internal/gps/cmd_unix.go b/internal/gps/cmd_unix.go index 47753e417e..906369ea41 100644 --- a/internal/gps/cmd_unix.go +++ b/internal/gps/cmd_unix.go @@ -35,6 +35,17 @@ func commandContext(ctx context.Context, name string, arg ...string) cmd { cancel: cancel, ctx: ctx, } + + // Force subprocesses into their own process group, rather than being in the + // same process group as the dep process. Because Ctrl-C sent from a + // terminal will send the signal to the entire currently running process + // group, this allows us to directly manage the issuance of signals to + // subprocesses. + c.Cmd.SysProcAttr = &syscall.SysProcAttr{ + Setpgid: true, + Pgid: 0, + } + return c } @@ -53,16 +64,6 @@ func (c cmd) CombinedOutput() ([]byte, error) { c.Cmd.Stdout = &b c.Cmd.Stderr = &b - // Force subprocesses into their own process group, rather than being in the - // same process group as the dep process. Ctrl-C sent from a terminal will - // send the signal to the entire running process group, so This allows us to - // directly manage the issuance of signals to subprocesses in that common - // case. - c.Cmd.SysProcAttr = &syscall.SysProcAttr{ - Setpgid: true, - Pgid: 0, - } - if err := c.Cmd.Start(); err != nil { return nil, err }