-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
go version go1.7.5 linux/amd64
What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build059832473=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
What did you do?
cmd := exec.Command("some command")
cmd.Stderr = ioutil.Discard
stdout, err := cmd.StdoutPipe()
if err != nil {
return "", "", err
}
if err := cmd.Start(); err != nil { // main.go:186
if cmd.Process != nil {
cmd.Process.Kill()
}
return "", "", err
}
.......func panicRecoverWrap(f func()) func() {
return func() {
defer func() {
if err := recover(); err != nil {
log.Printf("panic %v: %s", err, debug.Stack()) // util.go:28
}
}()
f()
}
}What did you expect to see?
Code execute without panic, maybe some errors
What did you see instead?
2017/04/11 08:00:41.089750 util.go:28: panic runtime error: invalid memory address or nil pointer dereference: goroutine 137 [running]:
runtime/debug.Stack(0xc42004f8c8, 0x67aa60, 0xc42000c100)
/usr/local/go/src/runtime/debug/stack.go:24 +0x79
main.panicRecoverWrap.func1.1()
/home/foobar/.GOPATH/src/foobar/util.go:28 +0x76
panic(0x67aa60, 0xc42000c100)
/usr/local/go/src/runtime/panic.go:458 +0x243
runtime.SetFinalizer(0x676c40, 0xc42000e420, 0x0, 0x0)
/usr/local/go/src/runtime/mfinal.go:303 +0x84
os.(*file).close(0xc42000e420, 0x6cd67f, 0x1e)
/usr/local/go/src/os/file_unix.go:146 +0xe0
os.(*File).Close(0xc42003c9a8, 0xc42004fcc0, 0xc420124630)
/usr/local/go/src/os/file_unix.go:132 +0x33
os/exec.(*Cmd).closeDescriptors(0xc42009e580, 0xc4200c4bc0, 0x3, 0x4)
/usr/local/go/src/os/exec/exec.go:262 +0x49
os/exec.(*Cmd).Start(0xc42009e580, 0x7e3820, 0xc42003c9a0)
/usr/local/go/src/os/exec/exec.go:365 +0x442
created by main.main.func3
/home/foobar/.GOPATH/src/foobar/main.go:186 +0x1cc