valyala / fasthttp

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http
MIT License
21.88k stars 1.76k forks source link

benchmark panics on client timing #1641

Closed peczenyj closed 1 year ago

peczenyj commented 1 year ago

Hello

The following benchmarks on client_timing_test.go are panic via runtime error

my environment

$ go version
go version go1.21.3 linux/amd64

$ go env
GO111MODULE='on'
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/weborama.office/tiago/.cache/go-build'
GOENV='/home/weborama.office/tiago/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/weborama.office/tiago/work/go/pkg/mod'
GONOPROXY='gitlab.nereides.weborama.com'
GONOSUMDB='gitlab.nereides.weborama.com'
GOOS='linux'
GOPATH='/home/weborama.office/tiago/work/go'
GOPRIVATE='gitlab.nereides.weborama.com'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.3'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/weborama.office/tiago/work/go/src/github.com/valyala/fasthttp/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build317392788=/tmp/go-build -gno-record-gcc-switches'

the output of each benchmark

$ go test -benchmem -run=^$ -bench ^BenchmarkClientGetTimeoutFastServer$ github.com/valyala/fasthttp
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x84c103]

goroutine 42 [running]:
github.com/valyala/fasthttp.(*fakeClientConn).SetWriteDeadline(0xc000000000?, {0x9df418?, 0xc0000402c0?, 0x0?})
    <autogenerated>:1 +0x23
github.com/valyala/fasthttp.(*transport).RoundTrip(0x0?, 0xc0002836c0, 0xc0000d4a80, 0xc000000000)
    /home/weborama.office/tiago/work/go/src/github.com/valyala/fasthttp/client.go:2867 +0x1fd
github.com/valyala/fasthttp.(*HostClient).doNonNilReqResp(0xc0002836c0, 0xc0000d4a80, 0xc000000000)
    /home/weborama.office/tiago/work/go/src/github.com/valyala/fasthttp/client.go:1373 +0x336
github.com/valyala/fasthttp.(*HostClient).do(0x40ec65?, 0xc000012180?, 0x18?)
    /home/weborama.office/tiago/work/go/src/github.com/valyala/fasthttp/client.go:1323 +0xae
github.com/valyala/fasthttp.(*HostClient).Do(0xc0002836c0, 0xc0000d4a80, 0xc000014320?)
    /home/weborama.office/tiago/work/go/src/github.com/valyala/fasthttp/client.go:1268 +0x173
github.com/valyala/fasthttp.(*Client).Do(0xc0000e0140, 0xc0000d4a80, 0xc000078de0?)
    /home/weborama.office/tiago/work/go/src/github.com/valyala/fasthttp/client.go:551 +0x5fc
github.com/valyala/fasthttp.doRequestFollowRedirects(0xc0000d4a80, 0xc000000000, {0xc00002e1c0?, 0xc0000d4a80?}, 0x10, {0x9da6c0, 0xc0000e0140})
    /home/weborama.office/tiago/work/go/src/github.com/valyala/fasthttp/client.go:1049 +0x194
github.com/valyala/fasthttp.doRequestFollowRedirectsBuffer(0xd11420?, {0x0, 0x0, 0x0}, {0xc00002e1c0, 0x1a}, {0x9da6c0, 0xc0000e0140})
    /home/weborama.office/tiago/work/go/src/github.com/valyala/fasthttp/client.go:1030 +0x1a5
github.com/valyala/fasthttp.clientGetURLDeadline.func1()
    /home/weborama.office/tiago/work/go/src/github.com/valyala/fasthttp/client.go:948 +0x105
created by github.com/valyala/fasthttp.clientGetURLDeadline in goroutine 41
    /home/weborama.office/tiago/work/go/src/github.com/valyala/fasthttp/client.go:945 +0x216
exit status 2
FAIL    github.com/valyala/fasthttp 0.006s
FAIL

and

$ go test -benchmem -run=^$ -bench ^BenchmarkClientDoFastServer$ github.com/valyala/fasthttp
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x84c103]

goroutine 26 [running]:
github.com/valyala/fasthttp.(*fakeClientConn).SetWriteDeadline(0xc00022c000?, {0x9df418?, 0xc000040280?, 0x0?})
    <autogenerated>:1 +0x23
github.com/valyala/fasthttp.(*transport).RoundTrip(0x0?, 0xc000283380, 0xc00022a000, 0xc00022c000)
    /home/weborama.office/tiago/work/go/src/github.com/valyala/fasthttp/client.go:2867 +0x1fd
github.com/valyala/fasthttp.(*HostClient).doNonNilReqResp(0xc000283380, 0xc00022a000, 0xc00022c000)
    /home/weborama.office/tiago/work/go/src/github.com/valyala/fasthttp/client.go:1373 +0x336
github.com/valyala/fasthttp.(*HostClient).do(0x40ec65?, 0xc000012150?, 0x18?)
    /home/weborama.office/tiago/work/go/src/github.com/valyala/fasthttp/client.go:1323 +0xae
github.com/valyala/fasthttp.(*HostClient).Do(0xc000283380, 0xc00022a000, 0xc000014310?)
    /home/weborama.office/tiago/work/go/src/github.com/valyala/fasthttp/client.go:1268 +0x173
github.com/valyala/fasthttp.(*Client).Do(0xc000148140, 0xc00022a000, 0xc000221f40?)
    /home/weborama.office/tiago/work/go/src/github.com/valyala/fasthttp/client.go:551 +0x5fc
github.com/valyala/fasthttp.BenchmarkClientDoFastServer.func2(0xc0000ac040)
    /home/weborama.office/tiago/work/go/src/github.com/valyala/fasthttp/client_timing_test.go:133 +0x219
testing.(*B).RunParallel.func1()
    /usr/local/go/src/testing/benchmark.go:815 +0xbf
created by testing.(*B).RunParallel in goroutine 18
    /usr/local/go/src/testing/benchmark.go:808 +0x113
exit status 2
FAIL    github.com/valyala/fasthttp 0.007s
FAIL
peczenyj commented 1 year ago

BTW I had some troubles to run all benchmarks

is it stable? Someone else can run it without issues?

erikdubbelboer commented 1 year ago

Thanks for the fix! I hadn't run the benchmarks in quite some time.