Skip to content
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

cmd/go: running test with -race flag panics for 1.10beta #23050

Closed
agnivade opened this issue Dec 8, 2017 · 6 comments
Closed

cmd/go: running test with -race flag panics for 1.10beta #23050

agnivade opened this issue Dec 8, 2017 · 6 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@agnivade
Copy link
Contributor

agnivade commented Dec 8, 2017

Please answer these questions before submitting your issue. Thanks!

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

1.10beta1

Does this issue reproduce with the latest release?

It passes when I run with tip.

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/agniva/play/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build209322330=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

I took the 1.10 beta release out for a spin. Found that my unit tests are failing when I run with the -race flag.

Here is a sample code -

package test

import (
	"testing"

	zmq "github.com/pebbe/zmq4"
)

func TestZMQ(t *testing.T) {
	//  Create server socket
	server, err := zmq.NewSocket(zmq.PULL)
	if err != nil {
		t.Error(err)
	}

	// Bind socket
	err = server.Bind("tcp://*:9001")
	if err != nil {
		t.Error(err)
	}

}

What did you expect to see?

The test to pass with both go test and go test -race commands.

What did you see instead?

Failure in go test -race

It works fine with 1.9.2 and with the tip. So, maybe this issue can be closed. However, just wanted to bring this to notice in case there is something that I have missed.

10:49:14-agniva-~/play/go/src/stdtest$go version
go version go1.9.2 linux/amd64
10:49:16-agniva-~/play/go/src/stdtest$go test -v  num_test.go 
=== RUN   TestZMQ
--- PASS: TestZMQ (0.00s)
PASS
ok  	command-line-arguments	0.003s
10:50:07-agniva-~/play/go/src/stdtest$go test -v -race num_test.go 
=== RUN   TestZMQ
--- PASS: TestZMQ (0.00s)
PASS
ok  	command-line-arguments	1.007s
10:50:13-agniva-~/play/go/src/stdtest$go1.10beta1 test -v  num_test.go 
=== RUN   TestZMQ
--- PASS: TestZMQ (0.00s)
PASS
ok  	command-line-arguments	(cached)
10:50:18-agniva-~/play/go/src/stdtest$go1.10beta1 test -v -race num_test.go 
=== RUN   TestZMQ
--- FAIL: TestZMQ (0.00s)
	num_test.go:13: zmq4 was installed with ZeroMQ version 4.2.1, but the application links with version 4.2.2
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x56cb3e]

goroutine 19 [running]:
testing.tRunner.func1(0xc4200e40f0)
	/home/agniva/sdk/go1.10beta1/src/testing/testing.go:739 +0x55b
panic(0x5bbe40, 0x8afb80)
	/home/agniva/sdk/go1.10beta1/src/runtime/panic.go:502 +0x24a
github.com/pebbe/zmq4.(*Socket).Bind(0x0, 0x5e69e6, 0xc, 0x0, 0x0)
	/home/agniva/play/go/src/github.com/pebbe/zmq4/zmq4.go:846 +0x4e
command-line-arguments.TestZMQ(0xc4200e40f0)
	/home/agniva/play/go/src/stdtest/num_test.go:17 +0xde
testing.tRunner(0xc4200e40f0, 0x5ee320)
	/home/agniva/sdk/go1.10beta1/src/testing/testing.go:774 +0x16e
created by testing.(*T).Run
	/home/agniva/sdk/go1.10beta1/src/testing/testing.go:821 +0x55c
FAIL	command-line-arguments	0.009s

10:50:55-agniva-~/play/go/src/stdtest$~/play/gosource/go/bin/go version
go version devel +6c877e5 Fri Dec 8 05:12:13 2017 +0000 linux/amd64
10:50:43-agniva-~/play/go/src/stdtest$~/play/gosource/go/bin/go test -v num_test.go 
=== RUN   TestZMQ
--- PASS: TestZMQ (0.00s)
PASS
ok  	command-line-arguments	0.003s
10:50:49-agniva-~/play/go/src/stdtest$~/play/gosource/go/bin/go test -v -race num_test.go 
=== RUN   TestZMQ
--- PASS: TestZMQ (0.00s)
PASS
ok  	command-line-arguments	(cached)

The error mentions a zmq version mismatch - zmq4 was installed with ZeroMQ version 4.2.1, but the application links with version 4.2.2.

So, just to be sure, I uninstalled and reinstalled my zmq library. And then uninstalled and reinstalled the zmq package. But still results are the same.

@ianlancetaylor
Copy link
Contributor

Is there a way that we can recreate the problem ourselves?

Does it make any difference if you set the environment variable GOCACHE=off?

@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels Dec 8, 2017
@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Dec 8, 2017
@agnivade
Copy link
Contributor Author

agnivade commented Dec 8, 2017

Ah yes, setting GOCAHE=off fixes it !

Yes, you can easily reproduce it with the code I pasted above. Just save it to a file and run it with -race flag. You need to install the libzmq library first though.

Here are the steps to install libzmq-

export ZMQ_VERSION=4.2.2

# Install build tools
sudo apt-get update && sudo apt-get install -y libtool pkg-config build-essential autoconf automake uuid-dev

# Download and install zmq
wget https://github.com/zeromq/libzmq/releases/download/v${ZMQ_VERSION}/zeromq-${ZMQ_VERSION}.tar.gz
tar xvzf zeromq-${ZMQ_VERSION}.tar.gz
cd zeromq-${ZMQ_VERSION} && ./configure && make -j 3 && sudo make install && sudo ldconfig

cd ..
# Check zmq installation
sudo ldconfig -p | grep zmq

Then do a go get github.com/pebbe/zmq4, and then you are ready to run the repro.

@mikioh
Copy link
Contributor

mikioh commented Dec 8, 2017

In general it's not a good idea to use the returned value from the failed function. In addition testing.Error is equivalent to testing.Log followed by testing.Fail; it continues the execution of test function; s/t.Error/t.Fatal/g fixes the bugs in your code.

Next time please take a look at https://github.com/golang/go/wiki/Questions and ask your question at more appropriate forums.

@mikioh mikioh closed this as completed Dec 8, 2017
@agnivade
Copy link
Contributor Author

agnivade commented Dec 8, 2017

Yes, the panic fixes. But the error is still there.

13:15:35-agniva-~/play/go/src/stdtest$go1.10beta1 test -v -race num_test.go 
=== RUN   TestZMQ
--- FAIL: TestZMQ (0.00s)
	num_test.go:13: zmq4 was installed with ZeroMQ version 4.2.1, but the application links with version 4.2.2
FAIL
FAIL	command-line-arguments	0.007s
13:15:52-agniva-~/play/go/src/stdtest$
13:15:56-agniva-~/play/go/src/stdtest$go1.10beta1 test -v num_test.go 
=== RUN   TestZMQ
--- PASS: TestZMQ (0.00s)
PASS
ok  	command-line-arguments	0.003s
13:16:00-agniva-~/play/go/src/stdtest$GOCACHE=off go1.10beta1 test -v -race num_test.go 
=== RUN   TestZMQ
--- PASS: TestZMQ (0.00s)
PASS
ok  	command-line-arguments	1.008s

It seems clear to me that the issue is related to setting GOCACHE with the -race flag. I can change the title to remove the word "panic". But the core problem still exists.

@mikioh
Copy link
Contributor

mikioh commented Dec 8, 2017

Please file a new issue that focuses on the root cause of zmq4 was installed with ZeroMQ version 4.2.1, but the application links with version 4.2.2 when using race detector and GOCACHE.

@agnivade
Copy link
Contributor Author

agnivade commented Dec 8, 2017

Done - #23057.

@golang golang locked and limited conversation to collaborators Dec 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants