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

invalid memory address or nil pointer dereference for firstByteReader'c #1775

Closed xuxiao415 closed 5 months ago

xuxiao415 commented 6 months ago
transmit panic runtime error: invalid memory address or nil pointer dereference stackInfo goroutine 1240808 [running]:
runtime/debug.Stack()
    /home/admin/.cache/tools/go-1.20.1/src/runtime/debug/stack.go:24 +0x65
proxyservice/handle.transmit.func1()
    /home/admin/66_20240506192018308_538271397_code/rpm_workspace/src/handle/handle.go:172 +0x66
panic({0xe48b60, 0x182e320})
    /home/admin/.cache/tools/go-1.20.1/src/runtime/panic.go:884 +0x213
github.com/valyala/fasthttp.(*firstByteReader).Read(0xc0002e8940?, {0xc001e2c000?, 0x0?, 0xc000867368?})
    /home/admin/66_20240506192018308_538271397_code/rpm_workspace/src/libs/github.com/fasthttp/server.go:851 +0x5c
bufio.(*Reader).Read(0xc00c8d8d80, {0xc0107807bb, 0x998d, 0xc000867388?})
    /home/admin/.cache/tools/go-1.20.1/src/bufio/bufio.go:237 +0x1bb
github.com/valyala/fasthttp.(*requestStream).Read(0xc005f9f3b0, {0xc0107807bb?, 0xc04d2febd0?, 0x0?})
    /home/admin/66_20240506192018308_538271397_code/rpm_workspace/src/libs/github.com/fasthttp/streaming.go:75 +0x2e5
github.com/valyala/bytebufferpool.(*ByteBuffer).ReadFrom(0xc000563320, {0x10afb80, 0xc005f9f3b0})
    /home/admin/66_20240506192018308_538271397_code/cmd/rpm_workspace/pkg/mod/github.com/valyala/bytebufferpool@v1.0.0/bytebuffer.go:45 +0x13e
io.copyBuffer({0x10af9a0, 0xc000563320}, {0x10afb80, 0xc005f9f3b0}, {0x0, 0x0, 0x0})
    /home/admin/.cache/tools/go-1.20.1/src/io/io.go:413 +0x14b
io.Copy(...)
    /home/admin/.cache/tools/go-1.20.1/src/io/io.go:386
github.com/valyala/fasthttp.(*Request).TakeBodyBufferFromStream(0xc00fcce000)

TakeBodyBufferFromStream's code:

func (req *Request) TakeBodyBufferFromStream() (*bytebufferpool.ByteBuffer, error) {
    bodyBuf := req.bodyBuffer()
    bodyBuf.Reset()
    if req.bodyStream != nil {
        _, err := io.Copy(bodyBuf, req.bodyStream)
        req.closeBodyStream() //nolint:errcheck
        if err != nil {
            return nil, err
        }
    }
    req.body = nil
    return bodyBuf, nil
}

my server is enable StreamRequestBody

I don't know why firstByteReader.c is nil. The problem is not reproducible at the moment, and I'm wondering if there are any directions I can investigate to troubleshoot this issue?

erikdubbelboer commented 6 months ago

You're going to have to share more code. Can you try and make a minimal example that reproduces the issue?

xuxiao415 commented 6 months ago

sorry,i can't reproduce it