When running this simple NestJS project with bun, there are some kind of memory leak that causes the memory comsumption to grow with each request. The same error does not occur when running the same project with NodeJS.
The memory leak problem only occurs when we include the NestJS-GraphQL module. If this module is removed, the memory consumption remains stable.
Tested with Bun v1.1.21 and NodeJS v22.3.0.
- Clone this repository
- Run
bun install
- Build and start the project by running
bun run build-node && bun ./dist/main.js
- Generate traffic to the server
http://localhost:3000/
. A simple tool for this is available in thetools
folder. Runnode tools/simple-traffic-test.js
to generate 300.000 requests to the server (will be executed one by one). - Monitor the memory comsumption of the bun-process. It will grow with each request.
Note that the requests to http://localhost:3000/
does not actually trigger any
GraphQL endpoints as this is available at http://localhost:3000/graphql
.
- Stop the bun-process
- Remove the
GraphQLModule
fromsrc/gql/gql.module.ts
by commenting out line10
-15
- Build and start the project by running
bun run build-node && bun ./dist/main.js
- Generate traffic to the server
http://localhost:3000/
. A simple tool for this is available in thetools
folder. Runnode tools/simple-traffic-test.js
to generate 300.000 requests to the server (will be executed one by one). - Monitor the memory comsumption of the bun-process. It will remain stable.
In our case, we build the project using Bun, and not the NestJS CLI. We do this
in a similar manner to what is set up in build.ts
. To use this, you can run
bun run build-bun && bun ./dist/main.js
.
The memory leak problem is still present when using this build step.
- Build and start the project by running
npm run build-node && node ./dist/main.js
- Generate traffic to the server
http://localhost:3000/
. A simple tool for this is available in thetools
folder. Runnode tools/simple-traffic-test.js
to generate 300.000 requests to the server (will be executed one by one). - Monitor the memory comsumption of the node-process. It will remain stable.