Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Conversation

@jmank88
Copy link
Collaborator

@jmank88 jmank88 commented Oct 13, 2017

What does this do / why do we need it?

This PR removes an extra command context and switches to use Cmd.Process.Kill() directly, rather than indirectly triggering the kill via cancelling the context.

Follow up from #1270.

@jmank88
Copy link
Collaborator Author

jmank88 commented Oct 13, 2017

@tamird care to take a look? Have I mistaken how this works or was intended?

@tamird
Copy link
Contributor

tamird commented Oct 13, 2017

Ah, I see -- nice catch.

Though perhaps now that we're not using context propagation for anything, it might be clearer and less error-prone to use exec.Command rather than exec.CommandContext and replace all calls to c.cancel() with calls to c.Process.Kill. That's what (*exec.Cmd).Run does anyway:

https://github.com/golang/go/blob/7f40c1214dd67cf171a347a5230da70bd8e10d32/src/os/exec/exec.go#L384:L393

Also, please be sure to include the full rationale in the commit message - it's a real PITA to have to look up the PR when digging through git blame.

@sdboyer
Copy link
Member

sdboyer commented Oct 13, 2017

ugh...i also found and fixed this yesterday, but i guess i didn't push up the change.

turns out, though, that this makes no difference at all in the normal case of ctrl-c sent from the CLI, because of...well, have a look at #1270, which i just put up.

Also, please be sure to include the full rationale in the commit message - it's a real PITA to have to look up the PR when digging through git blame.

yeah, we should move to this as a standard.

return cmd{ctx: ctx, Cmd: exec.Command(name, arg...)}
}

func (c cmd) kill() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this helper is helpful - just inline this into two places it's referenced.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signature doesn't match, so an annoymous wrapper function was required. No strong preference either way though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you mean because it returns an error? Still seems better to spell it out. Now that I look at it, the stopCancel binding isn't needed either:

...
defer time.AfterFunc(time.Minute, func() {
  _ = c.Cmd.Process.Kill()
}).Stop()

@tamird
Copy link
Contributor

tamird commented Oct 13, 2017

Text wrapping in the commit message is messed up, btw.

@jmank88 jmank88 changed the title gps: cmd_unix: break context chain to allow SIGINT to propogate uncontested gps: cmd_unix: remove extra command context; use Cmd.Process.Kill() directly Oct 15, 2017
@jmank88
Copy link
Collaborator Author

jmank88 commented Oct 15, 2017

Rebased.

Copy link
Contributor

@tamird tamird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !

_ = c.Cmd.Process.Kill()
} else {
stopCancel := time.AfterFunc(time.Minute, c.cancel).Stop
// After one minute, resort to kill.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd avoid this comment; the "one minute" bit is asking for rot.

@tamird
Copy link
Contributor

tamird commented Oct 23, 2017

@sdboyer can you merge this?

var b bytes.Buffer
c.Cmd.Stdout = &b
c.Cmd.Stderr = &b

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider restoring this =/

@sdboyer sdboyer merged commit 59b9d9f into golang:master Oct 23, 2017
@jmank88 jmank88 deleted the cmd_ctx branch October 24, 2017 00:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants