From 5e582109a36f1b03c17ac0f2c0ba8d1af81724a4 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez Date: Wed, 17 Jul 2024 00:02:26 -0400 Subject: [PATCH] Remove fasthttp.Request pool --- middleware/adaptor/adaptor.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/middleware/adaptor/adaptor.go b/middleware/adaptor/adaptor.go index f45701dad2..539aa3e24b 100644 --- a/middleware/adaptor/adaptor.go +++ b/middleware/adaptor/adaptor.go @@ -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) @@ -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 { @@ -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)