-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
feature requestNew feature to be addedNew feature to be addedv5.xIssue or pr related to Fastify v5Issue or pr related to Fastify v5
Milestone
Description
🚀 Feature Proposal
Fastify Request object is bound to the HTTP request lifecycle.
As a developer, I would expect that fastify creates a new Request object for every new request. While this is the case, fastify keeps object references across requests. This is due to the nature of prototype inheritance here.
This makes the code vulnerable to memory leaks: fastify/fastify-multipart#158 (comment)
We need to ensure that all properties are reset.
Motivation
As in other HTTP frameworks, the Request object is a new instance on every request. The developer shouldn't need to care about it. I propose to rethink that strategy because it's confusing and error-prone.
Example
fastify.decorateRequest('array', [])
fastify.post('/', async function (req, reply) {
req.array.push(1)
reply.code(200).send()
})
http.request(...) // array = [1]
http.request(...) // array = [1, 1]
.....
[ 1 ]
[ 1, 1 ]
[ 1, 1, 1 ]
[ 1, 1, 1, 1 ]
[ 1, 1, 1, 1, 1 ]
[ 1, 1, 1, 1, 1, 1 ]Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feature requestNew feature to be addedNew feature to be addedv5.xIssue or pr related to Fastify v5Issue or pr related to Fastify v5
Type
Projects
Status
Done