Closed
Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
go version devel +41908a5 Thu Dec 1 02:54:21 2016 +0000 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/bmizerany"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/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/dx/jcs03lw901vc05cjjqyjf8y00000gn/T/go-build129210763=/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 ran this benchmark:
func BenchmarkBug(b *testing.B) {
hts := httptest.NewServer(http.HandlerFunc(http.NotFound))
defer hts.Close()
cn, err := net.Dial("tcp", hts.Listener.Addr().String())
if err != nil {
panic(err)
}
defer func() {
println("CLOSING")
cn.Close() // <-- getting called too early?
}()
go io.Copy(ioutil.Discard, cn) // discard responses
reqBytes := []byte("GET / HTTP/1.1\r\nHost: e.com\r\n\r\n")
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_, err := cn.Write(reqBytes)
if err != nil {
panic(err)
}
}
println("DONE")
})
}
What did you expect to see?
PASS
What did you see instead?
$ go test -run=none -bench=BenchmarkBug
DONE
DONE
DONE
DONE
CLOSING
BenchmarkBug-4 DONE
DONE
DONE
DONE
CLOSING
panic: write tcp 127.0.0.1:55752->127.0.0.1:55751: write: broken pipe
goroutine 66 [running]:
backplane2/server.BenchmarkBug.func2(0xc42000c2e0)
/Users/bmizerany/src/bug/bench_test.go:261 +0xb7 // <--- The panic
testing.(*B).RunParallel.func1(0xc42011e0f0, 0xc42011e0e0, 0xc42011e0d8, 0xc4200b0000, 0xc420010810)
/usr/local/go/src/testing/benchmark.go:606 +0xc2
created by testing.(*B).RunParallel
/usr/local/go/src/testing/benchmark.go:607 +0x1af
FAIL bug 2.385s