Skip to content

runtime: nil pointer dereference hangs on macos instead of panicking. #50322

@inoc603

Description

@inoc603

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

$ go version
go version go1.17.3 darwin/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="/Users/inoc603/Library/Caches/go-build"
GOENV="/Users/inoc603/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/inoc603/pkg/mod"
GOOS="darwin"
GOPATH="/Users/inoc603"
GOROOT="/usr/local/Cellar/go/1.17.3/libexec"
GOSUMDB="sum.golang.google.cn"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.17.3/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/inoc603/src/github.com/inoc603/darwin_hang/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/1p/bpzkmcj16rs77yqhl8q9g1480000gp/T/go-build3663192036=/tmp/go-build -gno-record-gcc-switches -fno-common"

I removed GOPRIVATE, GOPROXY, GONOPROXY, GONOSUMDB from the output, which contains internal domains of my company. They're likely not related to this issue.

What did you do?

I created a new module with go mod init and built the following program with go build -o main

package main

func main() {
        var a *int
        *a += 1
}

Then run ./main

What did you expect to see?

The program panics for nil pointer dereference.

What did you see instead?

The program hangs, and can't be stopped with <ctrl+c> or kill command. I had to use kill -9 to kill it.

If I run it with sudo, the program panics as expected.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1054c42]

goroutine 1 [running]:
main.main()
        /Users/inoc603/src/github.com/inoc603/darwin_hang/main.go:5 +0x2

Runtime error like index out of range panics as expected with or without sudo.

package main

func main() {
	var b []string
	b[1] = ""
}

It looks like this is an issues specific to the machine I'm using. I run the same compiled binary on different macos machines, but unable to reproduce the same hanging problem.

I'm not sure what exactly happened under the hood, but maybe something is blocking the access of the invalid address 0x0. I understand it's probably impossible to consistently reproduce this elsewhere, so I hope someone can give me some direction for debugging this. Also I think the runtime should produce some kind of error instead of just hanging.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-DarwinWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions