Skip to content

Commit

Permalink
Remove fasthttp.Request pool
Browse files Browse the repository at this point in the history
  • Loading branch information
gaby committed Jul 17, 2024
1 parent 14e5c5b commit 5e58210
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions middleware/adaptor/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ import (
"github.com/valyala/fasthttp/fasthttpadaptor"
)

var reqPool = sync.Pool{
New: func() any {
return new(fasthttp.Request)
},
}

var ctxPool = sync.Pool{
New: func() any {
return new(fasthttp.RequestCtx)
Expand Down Expand Up @@ -138,9 +132,8 @@ func FiberApp(app *fiber.App) http.HandlerFunc {

func handlerFunc(app *fiber.App, h ...fiber.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
req := reqPool.Get().(*fasthttp.Request) //nolint:forcetypeassert,errcheck // overlinting
req.Reset()
defer reqPool.Put(req)
req := fasthttp.AcquireRequest()
defer fasthttp.ReleaseRequest(req)

// Convert net/http -> fasthttp request
if r.Body != nil {
Expand Down Expand Up @@ -176,6 +169,7 @@ func handlerFunc(app *fiber.App, h ...fiber.Handler) http.HandlerFunc {
// New fasthttp Ctx from pool
fctx := ctxPool.Get().(*fasthttp.RequestCtx) //nolint:forcetypeassert,errcheck // overlinting
fctx.Response.Reset()
fctx.Request.Reset()
defer ctxPool.Put(fctx)
fctx.Init(req, remoteAddr, nil)

Expand Down

0 comments on commit 5e58210

Please sign in to comment.