Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potentiel memory leak on simple request (bun + fastify + prisma) #12977

Closed
goldo opened this issue Jul 31, 2024 · 3 comments · Fixed by #15309
Closed

Potentiel memory leak on simple request (bun + fastify + prisma) #12977

goldo opened this issue Jul 31, 2024 · 3 comments · Fixed by #15309
Labels
bug Something isn't working needs triage

Comments

@goldo
Copy link

goldo commented Jul 31, 2024

What version of Bun is running?

1.1.22-canary.42+bec04c734

What platform is your computer?

Darwin 23.5.0 arm64 arm

What steps can reproduce the bug?

I made a small reproduction project with bun + fastify + prisma (sqlite):
https://github.com/goldo/bun-memory

bun install 
bun start
# then start requesting it and check the heapstats logs on the server
curl http://localhost:3010/ 
autocannon -c 30 -d 30 http://localhost:3010

What is the expected behavior?

Memory should be going down, after a while, at approx. the level of the beginning of the server (first request)

What do you see instead?

memory is going down just a little (GC), but stays really high

Additional information

This is a following issue of #7377

Investigation of potential bun memory leak

heapStats().objectTypeCounts check:

    heapStats().objectTypeCounts["Array"],
    heapStats().objectTypeCounts["Object"],
    heapStats().objectTypeCounts["Structure"]

at the beginning:

$ bun start
# curl http://localhost:3010
708 2252 7658

after autocannon -c 30 -d 30 http://localhost:3010 :

18905 54499 15811

After a few minutes (waiting for GC), the objectTypeCounts seems still high, and the memory usage is still high (101mb) vs initial (71mb):

# curl http://localhost:3010
17515 51800 15549

The problem seems to be the same with or without the fastify plugin.

@goldo goldo added bug Something isn't working needs triage labels Jul 31, 2024
@Jarred-Sumner
Copy link
Collaborator

A memory leak is indefinite growth in memory usage. 70 MB -> 100 MB is not clearly a leak. If you can make it go from 70 MB -> 1 GB, and then continue rising after receiving the same request volume then that is a leak.

@goldo
Copy link
Author

goldo commented Aug 5, 2024

On the full project, I got this:

  • before 05/08: bun (without build)
  • after 05/08: bun + build target node + run in node 22
    Screenshot 2024-08-05 at 16 11 51

@Jarred-Sumner
Copy link
Collaborator

Fixed in #15309

This will be part of the Bun v1.1.36 release, which is tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
2 participants