Skip to content

Go test silently segfaults #42816

Closed
Closed
@ocket8888

Description

@ocket8888

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

$ go version
go version go1.15.5 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/ocket8888/.cache/go-build"
GOENV="/home/ocket8888/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ocket8888/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ocket8888"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build153052688=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I wrote a test that segfaults. Looks something like:

import "strings"
import "testing"
import "github.com/apache/trafficcontrol/lib/go-tc"

func TestSomething(t *testing.T) {
	var ptr *tc.Alerts
	t.Log("About to do something")
	result, err := DoSomething() // Makes an HTTP request
	t.Log("alerts: %s", strings.Join(ptr.ToStrings(), ", "))
	if err != nil {
		t.Fatal("err was non-nil")
	}
	//...
}

What did you expect to see?

SIGSEGV in the output. Obviously because ptr is never assigned, it's nil and so ptr.ToStrings should segfault. That was a typo - but it was hard for me to find, because:

What did you see instead?

The log line never appears in the test output, and neither did any indication that a segfault had occurred. The test run didn't even fail, only other runs (called with t.Run in an outer scope) failed to run because of data inter-dependencies between the tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue 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