Open thibaultleouay opened 10 months ago
We have a same story on our bun service.
We will investigate this soon
Same issue when running within a container node:20-bookworm-slim
.
We got a memory leak with bun 1.0.26
too.
I will try to narrow it down to a simple example, but we are on a very small project, using mainly: fastify@4.24.3
and prisma@5.9.1
A simple HTTP call to this is leaking:
fastify.get("/health", async (request) => {
const count = await request.server.prisma.user.count();
return { ok: count > 0 };
});
(Without using prisma in this call, it was OK OFC)
Then I tried to build this code for node
, using bun build
, to run it in node 20, and it was a leaking a LOT less, and the GC could free the memory regularly, where it couldnt be possible when the same code (built or not) was run with bun.
I made my tests using htop
and autocannon
with params -c 30 -d 15
The issue is still here on the latest bun version 1.1.20, and we had to make our server self close gracefully when a certain memory limit is reached in order to avoid getting segfault crashes due to memory limits.
Hi, im no expert at all, but I tried to make a minimal reproduction with bun + fastify + prisma with results in readme https://github.com/goldo/bun-memory
This was fixed in https://github.com/oven-sh/bun/pull/12955, and will be available in the next release of Bun. To get it early, run bun upgrade --canary
The memory leak in this issue was caused by creating an AbortError when the HTTP request finished if the body was not yet consumed. This error object was never reachable from the garbage collector, and the garbage collector would take a very long time to ever clean these up because it’d only happen during a full collection
@goldo im not sure yet if the memory leak in this issue is the same as the one you’re running into. Can you open a new issue to track it?
@Jarred-Sumner thanks! I tried my small test project with this bun canary version and the problem seems to be still here. Here is the new issue: https://github.com/oven-sh/bun/issues/12977
What version of Bun is running?
1.0.14
What platform is your computer?
fly.io container
What steps can reproduce the bug?
We are running the bun from the latest docker image.
The code of our apps is here : https://github.com/openstatusHQ/openstatus/tree/822093042ce5b2ea028d51c0f090bdcfbb0cb302/apps/server
We have one machine that dont get garbage collected Here's what we see
Here's what we expect
and it happened twice for the same machine
Here's a snapshot https://snapshots.raintank.io/dashboard/snapshot/K7G90ajb9deOwkRtePmIAzAi7y9reE9v?orgId=2
What is the expected behavior?
No response
What do you see instead?
No response
Additional information
No response