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

reflect: slice index out of range #31801

Closed
fraenkel opened this issue May 2, 2019 · 4 comments
Closed

reflect: slice index out of range #31801

fraenkel opened this issue May 2, 2019 · 4 comments

Comments

@fraenkel
Copy link
Contributor

@fraenkel fraenkel commented May 2, 2019

Using go version devel +762953be28 Thu May 2 00:42:51 2019 +0000 linux/amd64

While debugging #31784, I received a panic:

stack
goroutine 274 [running]:
net/http.init.2.func1(0x0, 0x0, 0x0)
	/home/fraenkel/workspace/go/src/net/http/export_test.go:53 +0x95
net/http.(*Client).do.func1(0xc0001cdef0, 0xc0001cdef8)
	/home/fraenkel/workspace/go/src/net/http/client.go:516 +0x4b
panic(0x8ba1c0, 0xa21df0)
	/home/fraenkel/workspace/go/src/runtime/panic.go:619 +0x1b2
reflect.Value.Index(0x8b3420, 0xc0004a2258, 0x1b7, 0x2e, 0x76, 0x4, 0x1a8)
	/home/fraenkel/workspace/go/src/reflect/value.go:938 +0x1fe
fmt.(*pp).printValue(0xc0003000c0, 0x8b3420, 0xc0004a2258, 0x1b7, 0x76, 0x3)
	/home/fraenkel/workspace/go/src/fmt/print.go:839 +0x87e
fmt.(*pp).printValue(0xc0003000c0, 0x91a7a0, 0xc0004a2258, 0x1b9, 0x76, 0x2)
	/home/fraenkel/workspace/go/src/fmt/print.go:789 +0x1b45
fmt.(*pp).printValue(0xc0003000c0, 0x963aa0, 0xc0004a2000, 0x199, 0xc000000076, 0x1)
	/home/fraenkel/workspace/go/src/fmt/print.go:789 +0x1b45
fmt.(*pp).printValue(0xc0003000c0, 0x960920, 0xc0004a2000, 0x16, 0x76, 0x0)
	/home/fraenkel/workspace/go/src/fmt/print.go:859 +0x194a
fmt.(*pp).printArg(0xc0003000c0, 0x960920, 0xc0004a2000, 0xc000000076)
	/home/fraenkel/workspace/go/src/fmt/print.go:695 +0x2b4
fmt.(*pp).doPrintf(0xc0003000c0, 0x9671df, 0x4, 0xc0001cd668, 0x1, 0x1)
	/home/fraenkel/workspace/go/src/fmt/print.go:1009 +0x15b
fmt.Fprintf(0xa2cb20, 0xc000010018, 0x9671df, 0x4, 0xc0001cd668, 0x1, 0x1, 0x4f9b7e, 0x8e4500, 0xd8ffa0)
	/home/fraenkel/workspace/go/src/fmt/print.go:199 +0x72
fmt.Printf(...)
	/home/fraenkel/workspace/go/src/fmt/print.go:208
net/http_test.TestTransportMaxConnsPerHost.func2.2.1(0xa3d3a0, 0xc0004a2000, 0xd80001, 0x0)
	/home/fraenkel/workspace/go/src/net/http/transport_test.go:625 +0x9f
net/http.http2traceGotConn(0xc000494600, 0xc000480180)
	/home/fraenkel/workspace/go/src/net/http/h2_bundle.go:8995 +0x192
net/http.(*http2Transport).RoundTripOpt(0xc0002dd8c0, 0xc000494600, 0xc000306c00, 0xc000494600, 0x0, 0x0)
	/home/fraenkel/workspace/go/src/net/http/h2_bundle.go:6866 +0x13b
net/http.(*http2Transport).RoundTrip(0xc0002dd8c0, 0xc000494600, 0x0, 0xc000202d60, 0x5)
	/home/fraenkel/workspace/go/src/net/http/h2_bundle.go:6829 +0x3a
net/http.(*Transport).roundTrip(0xc0002c0640, 0xc000494600, 0x0, 0xc000202d76, 0xc000028b20)
	/home/fraenkel/workspace/go/src/net/http/transport.go:511 +0x734
net/http.(*Transport).RoundTrip(0xc0002c0640, 0xc000494600, 0xc0002c0640, 0x0, 0x0)
	/home/fraenkel/workspace/go/src/net/http/roundtrip.go:17 +0x35
net/http.send(0xc000494600, 0xa2c620, 0xc0002c0640, 0x0, 0x0, 0x0, 0xc00013e050, 0x0, 0x1, 0x0)
	/home/fraenkel/workspace/go/src/net/http/client.go:250 +0x4d5
net/http.(*Client).send(0xc000306660, 0xc000494600, 0x0, 0x0, 0x0, 0xc00013e050, 0x0, 0x1, 0xc00016ad98)
	/home/fraenkel/workspace/go/src/net/http/client.go:174 +0xfa
net/http.(*Client).do(0xc000306660, 0xc000494600, 0x0, 0x0, 0x0)
	/home/fraenkel/workspace/go/src/net/http/client.go:641 +0x460
net/http.(*Client).Do(...)
	/home/fraenkel/workspace/go/src/net/http/client.go:509
net/http_test.TestTransportMaxConnsPerHost.func2.2()
	/home/fraenkel/workspace/go/src/net/http/transport_test.go:637 +0x22e
net/http_test.TestTransportMaxConnsPerHost.func2.3(0xc0001b5200, 0xc000306ae0)
	/home/fraenkel/workspace/go/src/net/http/transport_test.go:653 +0x4d
created by net/http_test.TestTransportMaxConnsPerHost.func2
	/home/fraenkel/workspace/go/src/net/http/transport_test.go:651 +0x2be
exit status 2

I added the following line

diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go
index 44a935960e..be8420478f 100644
--- a/src/net/http/transport_test.go
+++ b/src/net/http/transport_test.go
@@ -622,6 +622,7 @@ func TestTransportMaxConnsPerHost(t *testing.T) {
                doReq := func() {
                        trace := &httptrace.ClientTrace{
                                GotConn: func(connInfo httptrace.GotConnInfo) {
+                                       fmt.Printf("%#v\n", connInfo.Conn)
                                        if !connInfo.Reused {
                                                atomic.AddInt32(&gotConnCnt, 1)
                                        }

And I am running the following command
go test -test.short=0 -run TestTransportMaxConnsPerHost$ -count=1000 -v > log

@cuonglm

This comment has been minimized.

Copy link
Contributor

@cuonglm cuonglm commented May 2, 2019

It's interesting that using %+v does not trigger the panic.

@martisch

This comment has been minimized.

Copy link
Member

@martisch martisch commented May 2, 2019

Running with go test -race -test.short=0 -run TestTransportMaxConnsPerHost$ -count=1000 -v
shows there is a data race for accessing the slice for which the index panics. Likely between fmt checking that index < len and and accesing that index from the slice the slice has been updated.

@martisch martisch closed this May 2, 2019
@zeisss

This comment has been minimized.

Copy link

@zeisss zeisss commented Nov 15, 2019

Are any more infos on this available?

We are seeing the same problem when using fmt.Printf() with either %+v and %#v while trying to understand why our HTTP Tracers seem to get a nil connection provided to GotConn(): Calling info.Conn.RemoteAddr() panics with:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x492195f]
$ go version
go version go1.13 darwin/amd64
@cuonglm

This comment has been minimized.

Copy link
Contributor

@cuonglm cuonglm commented Nov 15, 2019

Are any more infos on this available?

We are seeing the same problem when using fmt.Printf() with either %+v and %#v while trying to understand why our HTTP Tracers seem to get a nil connection provided to GotConn(): Calling info.Conn.RemoteAddr() panics with:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x492195f]
$ go version
go version go1.13 darwin/amd64

It's fixed in 1.13.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.