-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
Description
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
):
- with
sh
and onlysleep
, https://play.golang.org/p/g-Nm3XDhu7, result:Error: "signal: killed", time: 1.001670305s
- with
sh
andsleep
andecho
, https://play.golang.org/p/BtLj2ztnCF, result:Error: "signal: killed", time: 5.015074382s
- with
bash
and onlysleep
, https://play.golang.org/p/L41fxmEkA9, result:Error: "signal: killed", time: 1.001631559s
- with
bash
andsleep
andecho
, https://play.golang.org/p/EUYBO2tYM6, result:Error: "signal: killed", time: 5.01418195s
For go version go1.9.2 linux/amd64
:
docker run --rm -v $PWD:/app -w /app golang:latest go run exec_cancelation_bug.go
for https://play.golang.org/p/BtLj2ztnCF, result:Error: "signal: killed", time: 5.005615527s
- same for https://play.golang.org/p/g-Nm3XDhu7, result:
Error: "signal: killed", time: 5.006439868s
- same for https://play.golang.org/p/L41fxmEkA9, result:
Error: "signal: killed", time: 1.001275981s