We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
go version
$ go version go version go1.20.1 darwin/amd64
Yes.
go env
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="/Users/jm/go/bin" GOCACHE="/Users/jm/Library/Caches/go-build" GOENV="/Users/jm/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/jm/go/pkg/mod" GOOS="darwin" GOPATH="/Users/jm/go" GOROOT="/Users/jm/.gobrew/versions/1.20.1/go" GOSUMDB="sum.golang.google.cn" GOTMPDIR="" GOTOOLDIR="/Users/jm/.gobrew/versions/1.20.1/go/pkg/tool/darwin_amd64" GOVCS="" GOVERSION="go1.20.1" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOWORK="" CGO_CFLAGS="-O2 -g" CGO_CPPFLAGS="" CGO_CXXFLAGS="-O2 -g" CGO_FFLAGS="-O2 -g" CGO_LDFLAGS="-O2 -g" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ml/wcc43cv538gg10sbkqd_z7980000gp/T/go-build2586553286=/tmp/go-build -gno-record-gcc-switches -fno-common"
GO111MODULE="" GOARCH="amd64" GOBIN="/Users/jm/go/bin" GOCACHE="/Users/jm/Library/Caches/go-build" GOENV="/Users/jm/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/jm/go/pkg/mod" GOOS="darwin" GOPATH="/Users/jm/go" GOROOT="/Users/jm/.gobrew/versions/1.20.1/go" GOSUMDB="sum.golang.google.cn" GOTMPDIR="" GOTOOLDIR="/Users/jm/.gobrew/versions/1.20.1/go/pkg/tool/darwin_amd64" GOVCS="" GOVERSION="go1.20.1" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOWORK="" CGO_CFLAGS="-O2 -g" CGO_CPPFLAGS="" CGO_CXXFLAGS="-O2 -g" CGO_FFLAGS="-O2 -g" CGO_LDFLAGS="-O2 -g" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ml/wcc43cv538gg10sbkqd_z7980000gp/T/go-build2586553286=/tmp/go-build -gno-record-gcc-switches -fno-common"
Run below command with go1.20.1:
package main import ( "context" "os/exec" "time" ) type Command struct { exec.Cmd Cancel context.CancelFunc } func main() { ctx, cancel := context.WithCancel(context.Background()) go func() { time.Sleep(time.Millisecond * 100) cancel() }() c := New("sleep 1; echo ok") go func() { <-ctx.Done() c.Cancel() }() c.Run() } func New(command string) *Command { ctx, cancel := context.WithCancel(context.Background()) cmd := exec.CommandContext(ctx, "bash", "-c", command) c := &Command{ Cmd: *cmd, Cancel: cancel, } return c }
Command should run without any panic.
Panic with below error:
panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x107baf9] goroutine 20 [running]: os.(*Process).signal(0x0?, {0x10bbfd0?, 0x111e448?}) /Users/jm/.gobrew/versions/1.20.1/go/src/os/exec_unix.go:63 +0x39 os.(*Process).Signal(...) /Users/jm/.gobrew/versions/1.20.1/go/src/os/exec.go:138 os.(*Process).kill(...) /Users/jm/.gobrew/versions/1.20.1/go/src/os/exec_posix.go:67 os.(*Process).Kill(...) /Users/jm/.gobrew/versions/1.20.1/go/src/os/exec.go:123 os/exec.CommandContext.func1() /Users/jm/.gobrew/versions/1.20.1/go/src/os/exec/exec.go:449 +0x33 os/exec.(*Cmd).watchCtx(0xc000134000, 0xc000102120) /Users/jm/.gobrew/versions/1.20.1/go/src/os/exec/exec.go:765 +0xf3 created by os/exec.(*Cmd).Start /Users/jm/.gobrew/versions/1.20.1/go/src/os/exec/exec.go:743 +0x9f3 exit status 2
The text was updated successfully, but these errors were encountered:
The bug is in your code, Cmd shouldn't be copied.
Sorry, something went wrong.
No branches or pull requests
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Run below command with go1.20.1:
What did you expect to see?
Command should run without any panic.
What did you see instead?
Panic with below error:
The text was updated successfully, but these errors were encountered: