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

... Panic: runtime error: invalid memory address or nil pointer dereference (PC=0x1086B58) #20495

Closed
archisgore opened this issue May 25, 2017 · 2 comments

Comments

@archisgore
Copy link

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8.1 darwin/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/archis/Polyverse"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.8.1/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.8.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/sk/yhx1981133v5xxjfpkrgbvfr0000gn/T/go-build577863162=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

I created a function to clone http.Request into a smaller subset that we can serialize for logging/etc. When I test it through a Unit test, it fails.

Code captured in Gist here: https://gist.github.com/archisgore/7be552ba471af9ee7dbe4b2a9a8e26f6

Go playground link: https://play.golang.org/p/lgE0r8wgOK

What did you expect to see?

I expected the test from the Gist to pass.

What did you see instead?

When I run the code from the Gist, it'll crash with this error:

Archishmats-MacBook-Pro-2:request archis$ go test

----------------------------------------------------------------------
PANIC: SerializableRequest_test.go:18: BackendSuite.TestClone

... Panic: runtime error: invalid memory address or nil pointer dereference (PC=0x1057418)

/usr/local/Cellar/go/1.8.1/libexec/src/runtime/panic.go:489
  in gopanic
/usr/local/Cellar/go/1.8.1/libexec/src/runtime/panic.go:63
  in panicmem
/usr/local/Cellar/go/1.8.1/libexec/src/runtime/signal_unix.go:290
  in sigpanic
SerializableRequest_test.go:25
  in BackendSuite.TestClone
/usr/local/Cellar/go/1.8.1/libexec/src/reflect/value.go:302
  in Value.Call
/usr/local/Cellar/go/1.8.1/libexec/src/runtime/asm_amd64.s:2197
  in goexit
OOPS: 0 passed, 1 PANICKED
--- FAIL: TestBackend (0.00s)
FAIL
exit status 1
FAIL	_/Users/archis/archis-dev/request	0.014s

Here's the interesting part - when I ran it using Go playground, it worked. What I can't tell is whether this only manifests itself when running through the test framework (and whether it's something to do with go test or the gopkg.in/check.v1 package.

Also if you comment out the line:

rc.Host = r.Host

The test also will run without panicking (if not pass).

@davecheney
Copy link
Contributor

davecheney commented May 25, 2017 via email

@archisgore
Copy link
Author

Ah thanks! That was a weird one.

I remember using r.Host on both sides (as opposed to r.URL.Host). But when I add:

rc.URL = r.URL

The Host copy works.

@golang golang locked and limited conversation to collaborators May 25, 2018
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

3 participants