Skip to content

runtime: cgo stuck because of go signal handler went into dead loop if pid=1 #59569

Open
@cocktail828

Description

@cocktail828

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

$ go version
go version go1.19 linux/amd64

Does this issue reproduce with the latest release?

Sure

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

go env Output
$ go env
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/root/go/pkg/mod"
GONOPROXY=
GONOSUMDB=
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2188387714=/tmp/go-build -gno-record-gcc-switches"

What did you do?

The bug found in go1.10.3 at first, the I update go to go1.19, it happends too. I find the root case lives here:

In almost all real cases the program is about to crash, but in my situation, it does not after usleep. But why, I cannot explain!!!.

Then I try fix it myself with the following patch:

	raise(sig)
	// Give the signal a chance to be delivered.
	// In almost all real cases the program is about to crash,
	// so sleeping here is not a waste of time.
	usleep(1000)

	switch sig {
	case _SIGSEGV, _SIGABRT, _SIGFPE, _SIGILL, _SIGBUS:
		print("fatal error: unexpected signal during runtime execution\n")
		signame := signame(sig)
		if signame != "" {
			print("[signal ", signame)
		} else {
			print("[signal ", hex(sig))
		}
		print(" code=", hex(c.sigcode()), " addr=", hex(c.sigaddr()), "]\n")
		dieFromSignal(sig)

	default:
		// If the signal didn't cause the program to exit, restore the
		// Go signal handler and carry on.
		//
		// We may receive another instance of the signal before we
		// restore the Go handler, but that is not so bad: we know
		// that the Go program has been ignoring the signal.
		setsig(sig, abi.FuncPCABIInternal(sighandler))
	}

What did you expect to see?

panic

What did you see instead?

See #56649

Metadata

Metadata

Assignees

Labels

NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

Todo

Relationships

None yet

Development

No branches or pull requests

Issue actions