Injectable instances can have references to Request objects and can hold it forewer in request scope #13365
Closed
5 of 15 tasks
Labels
needs triage
This issue has not been looked into
Is there an existing issue for this?
Current behavior
When nest handle any request on first time - it gets metadata for controller's handler and stores it in cache forever.
When that controller utilizes the request object, that injected by REQUEST token - it will have reference to request object in scope and will hold it forewer, because of cache.
Minimum reproduction code
https://github.com/breeeew/nestjs-leak-reproduction
FIX
Steps to reproduce
Expected behavior
All unused objects must be collected by gc
Package
@nestjs/common
@nestjs/core
@nestjs/microservices
@nestjs/platform-express
@nestjs/platform-fastify
@nestjs/platform-socket.io
@nestjs/platform-ws
@nestjs/testing
@nestjs/websockets
Other package
No response
NestJS version
latest
Packages versions
Node.js version
18, 20
In which operating systems have you tested?
Other
Our case: sometimes user requests some handler in request scope, that downloads a huge json - and that json have been parsed and holds a huge amount of memory. And it also slows down garbage collectiong process (while collecting it increases cpu usage and memory usage by nodejs)
The text was updated successfully, but these errors were encountered: