Skip to content
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

os/exec: CommandContext with timeout with multiple subprocesses isn't canceled #22485

Closed
msoap opened this issue Oct 29, 2017 · 2 comments
Closed

Comments

@msoap
Copy link

msoap commented Oct 29, 2017

What version of Go are you using (go version)?

  • go version go1.7.6 darwin/amd64
  • go version go1.8.5 darwin/amd64
  • go version go1.9.2 darwin/amd64
  • go version go1.9.2 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/msa/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.9.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.9.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/nf/3r6ynmsn52ndstns_gkkfy580000gn/T/go-build091401128=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

I'm run the exec.CommandContext with 1 second timeout with a shell command that is delayed 5 seconds.

package main

import (
	"context"
	"fmt"
	"os/exec"
	"time"
)

func main() {
	ctx, cancelFn := context.WithTimeout(context.Background(), time.Second)
	defer cancelFn()

	t := time.Now()
	_, err := exec.CommandContext(ctx, "sh", "-c", `sleep 5; echo ok`).CombinedOutput()
	fmt.Printf("Error: %q, time: %s\n", err, time.Now().Sub(t))
}

What did you expect to see?

The command must be canceled after 1 second.

What did you see instead?

Command is delayed 5 seconds.

Error: "signal: killed", time: 5.011181921s:

I assume that this is due to the number of processes that are started.
That's few examples (for go version go1.9.2 darwin/amd64):

For go version go1.9.2 linux/amd64:

@msoap
Copy link
Author

msoap commented Oct 29, 2017

Maybe is the same problem in #22381

@msoap msoap changed the title exec.CommandContext with timeout with multiple subprocesses isn't canceled os/exec: CommandContext with timeout with multiple subprocesses isn't canceled Oct 29, 2017
@ianlancetaylor
Copy link
Contributor

It's not quite #22381, but closing as dup of #18874.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants