Skip to content

cmd/run: Can't interrupt go run #58580

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

Closed
palsivertsen opened this issue Feb 17, 2023 · 2 comments
Closed

cmd/run: Can't interrupt go run #58580

palsivertsen opened this issue Feb 17, 2023 · 2 comments

Comments

@palsivertsen
Copy link

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

$ go version
go version go1.20.1 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/pal/.cache/go-build"
GOENV="/home/pal/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/pal/projects/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/pal/projects/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1890082785=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.20.1 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.20.1
uname -sr: Linux 6.1.12-arch1-1
/usr/lib/libc.so.6: GNU C Library (GNU libc) stable release version 2.37.

What did you do?

I used the following example from os/signal:

package main

import (
	"fmt"
	"os"
	"os/signal"
)

func main() {
	// Set up channel on which to send signal notifications.
	// We must use a buffered channel or risk missing the signal
	// if we're not ready to receive when the signal is sent.
	c := make(chan os.Signal, 1)

	// Passing no signals to Notify means that
	// all signals will be sent to the channel.
	signal.Notify(c)

	// Block until any signal is received.
	s := <-c
	fmt.Println("Got signal:", s)
}

I ran the program using go run ./main.go. As expected it'll wait for any signal, print the first signal and then exit. No surprises here.

Then I tried to interrupt the program using the kill command:
image
This has no effect. If I send the kill signal, then the child process is orphaned:
image

Interrupting the program using CTRL^C works as normal.

What did you expect to see?

Interrupting go run should propagate the signal to the child process.

What did you see instead?

go run ignores external(?) signals.

@vatine
Copy link

vatine commented Feb 17, 2023

I would not normally expect a program to propagate signals it receives to its children. The reason that the SIGINT triggered by Ctrl-C is sent to the child program in your case is because that signal is sent to the "process running in the foreground, attached to the terminal", which would not be go run, but the program started by go run.

@seankhliao
Copy link
Member

Duplicate of #40467

@seankhliao seankhliao marked this as a duplicate of #40467 Feb 17, 2023
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Feb 17, 2023
@golang golang locked and limited conversation to collaborators Feb 17, 2024
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

4 participants