Skip to content

net/http/httptest: 'Server.CloseClientConnections' triggers panic in 'Server.Close` call #19729

@gyuho

Description

@gyuho

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

go master branch as of today

go version devel +ecc6a81 Sat Mar 25 00:35:35 2017 +0000 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/gyuho/go"
GORACE=""
GOROOT="/home/gyuho/go-master"
GOTOOLDIR="/home/gyuho/go-master/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build055947270=/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?

etcd(https://github.com/coreos/etcd/blob/master/integration/cluster.go#L717-L720) calls

for _, hs := range m.hss {
	hs.CloseClientConnections()
	hs.Close()
}

where hs is *httptest.Server

What did you expect to see?

It should not panic from nil pointer dereference in the following httptest.Server.Close

What did you see instead?

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=0x0 pc=0x866e92]

goroutine 26 [running]:
testing.tRunner.func1(0xc42017cf70)
	/home/gyuho/go-master/src/testing/testing.go:624 +0x25d
panic(0xc7f6c0, 0x1266d40)
	/home/gyuho/go-master/src/runtime/panic.go:489 +0x26a
net/http/httptest.(*Server).Close(0xc4200679d0)
	/home/gyuho/go-master/src/net/http/httptest/server.go:212 +0x2a2
github.com/coreos/etcd/integration.(*member).Close(0xc4201a8240)
	/home/gyuho/go/src/github.com/coreos/etcd/integration/cluster.go:719 +0xc3
github.com/coreos/etcd/integration.(*member).Terminate(0xc4201a8240, 0xc42017cf70)
	/home/gyuho/go/src/github.com/coreos/etcd/integration/cluster.go:773 +0x11b
github.com/coreos/etcd/integration.(*cluster).Terminate(0xc4201c01a0, 0xc42017cf70)
	/home/gyuho/go/src/github.com/coreos/etcd/integration/cluster.go:317 +0x56
github.com/coreos/etcd/integration.(*ClusterV3).Terminate(0xc4201e83c0, 0xc42017cf70)
	/home/gyuho/go/src/github.com/coreos/etcd/integration/cluster.go:897 +0x90
github.com/coreos/etcd/clientv3/naming.TestGRPCResolver(0xc42017cf70)
	/home/gyuho/go/src/github.com/coreos/etcd/clientv3/naming/grpc_test.go:84 +0x801
testing.tRunner(0xc42017cf70, 0xdde678)
	/home/gyuho/go-master/src/testing/testing.go:659 +0x98
created by testing.(*T).Run
	/home/gyuho/go-master/src/testing/testing.go:701 +0x2d5
exit status 2

I confirm that after CloseClientConnections, s.client in Close is nil--so panic-ed.

// Also close the client idle connections.
if t, ok := s.client.Transport.(closeIdleTransport); ok {
	t.CloseIdleConnections()
}

It was added from fbf4dd9#diff-4d34e6d5bd560e4ac6fd23ee5d9bda5fR209

Or are we doing anything wrong here?

hs.CloseClientConnections()
hs.Close()

Thanks a lot in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions