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.87k stars 1.76k forks source link

Panic on reading request header #1564

Closed lemonlinger closed 11 months ago

lemonlinger commented 1 year ago

The calling stack is below

panic: runtime error: slice bounds out of range [:4668] with capacity 4096
 goroutine 1755837666 [running]:
 bufio.(*Reader).Peek(0xc00cc283c0, 0x2ef)
 /usr/local/go/src/bufio/bufio.go:156 +0x191
 github.com/valyala/fasthttp.mustPeekBuffered(0xc00cc283c0)
 /root/go/pkg/mod/github.com/valyala/fasthttp@v1.38.0/header.go:3235 +0x25
 github.com/valyala/fasthttp.(*RequestHeader).tryRead(0xc00fd14c00, 0xc00cc283c0, 0x1)
 /root/go/pkg/mod/github.com/valyala/fasthttp@v1.38.0/header.go:2065 +0x2e5
 github.com/valyala/fasthttp.(*RequestHeader).readLoop(0xc064df9c38, 0xc00cc283c0, 0x1)
 /root/go/pkg/mod/github.com/valyala/fasthttp@v1.38.0/header.go:1971 +0x4d
 github.com/valyala/fasthttp.(*RequestHeader).Read(...)
 /root/go/pkg/mod/github.com/valyala/fasthttp@v1.38.0/header.go:1962
 github.com/valyala/fasthttp.(*Server).serveConn(0xc00102cd80, {0x17dafb8, 0xc064df9c38})
 /root/go/pkg/mod/github.com/valyala/fasthttp@v1.38.0/server.go:2186 +0x953
 github.com/valyala/fasthttp.(*workerPool).workerFunc(0xc002b32000, 0xc030f6dc20)
 /root/go/pkg/mod/github.com/valyala/fasthttp@v1.38.0/workerpool.go:224 +0xa9
 github.com/valyala/fasthttp.(*workerPool).getCh.func1()
 /root/go/pkg/mod/github.com/valyala/fasthttp@v1.38.0/workerpool.go:196 +0x38
 created by github.com/valyala/fasthttp.(*workerPool).getCh
 /root/go/pkg/mod/github.com/valyala/fasthttp@v1.38.0/workerpool.go:195 +0x1b5

But I can't reproduce this panic and got nothing about the request.

I use go1.17 and fasthttp@v1.38.0.

Any advice? Thanks.

li-jin-gou commented 1 year ago

My guess is that your asynchronous use of fasthttp's ctx or request is causing the problem. @lemonlinger

lemonlinger commented 1 year ago

My guess is that your asynchronous use of fasthttp's ctx or request is causing the problem. @lemonlinger

In my own code, I didn't use fasthttp context in an asynchronous way. But I did enable StreamRequestBody of fasthttp server. Is that probably related ?

li-jin-gou commented 1 year ago

My guess is that your asynchronous use of fasthttp's ctx or request is causing the problem. @lemonlinger

In my own code, I didn't use fasthttp context in an asynchronous way. But I did enable StreamRequestBody of fasthttp server. Is that probably related ?

Not sure, but you can try upgrading to the latest fasthttp to try it out.

erikdubbelboer commented 1 year ago

Please try the latest version of fasthttp. If it still happens can you share the code of your handler so we can see what is happening there?

lemonlinger commented 1 year ago

Will do. Thanks