Skip to content

Understanding Memory Allocation + Debug memory Leak #4200

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

Closed
XciD opened this issue Jul 4, 2023 · 5 comments
Closed

Understanding Memory Allocation + Debug memory Leak #4200

XciD opened this issue Jul 4, 2023 · 5 comments
Labels
needs more info issues that need more info from the author question

Comments

@XciD
Copy link

XciD commented Jul 4, 2023

Details

We have migrated one of our top nodejs application from pm2 to containers + kubernetes.
This migration gave us way more information about our running code and we have fixe multiple memory leak related to dependencies.

After multiple iteration, we successfully have the heap quite stabilized but we seems to still having a leak.
A chart is worth a thousand words:
4RtF8

As you can see, the heap sounds normal, but the external memory have a good leak representation.

Node is running with --max-heap-size=768 option

What I dont understand is this error:

<--- Last few GCs --->

[1:0x69e3660] 45788793 ms: Mark-Compact (reduce) 716.8 (728.9) -> 716.8 (728.9) MB, 610.99 / 0.00 ms  (average mu = 0.474, current mu = 0.000) last resort; GC in old space requested
[1:0x69e3660] 45789396 ms: Mark-Compact (reduce) 716.8 (728.9) -> 716.8 (728.9) MB, 602.47 / 0.00 ms  (average mu = 0.305, current mu = 0.001) last resort; GC in old space requested


<--- JS stacktrace --->

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

If I understand the gc trace correctly, the heap is at 716MB, but why not on the graph ?
Also, how to find a leak on the external memory ?

Node.js version

v20.3.1

Example code

No response

Operating system

Linux 5.10.178-162.673.amzn2.x86_64 #1 SMP Mon Apr 24 23:34:06 UTC 2023 x86_64 GNU/Linux

Scope

runtime

Module and version

Not applicable.

@preveen-stack
Copy link
Contributor

cc @nodejs/v8

@gireeshpunathil
Copy link
Member

If I understand the gc trace correctly, the heap is at 716MB, but why not on the graph ?

you are right, the heap usage is not correctly reflected in the graph. which tool is that?

Also, how to find a leak on the external memory ?

it is hard. but this is a rough sketch of what you can do:

  • take a heap dump
  • load it in chrome dev tools
  • navigate through all array buffers and shared array buffers in the heap
  • find sizes of each and sum those up
  • see if that tallies with the external memory size.
  • if yes and you are not happy with that, walk through the dominator tree and see where those are allocated.
  • if no, look out for presence of native modules and see what those are allocating.

if you want to take that path and have questions on any steps let me know!

@preveen-stack preveen-stack added the needs more info issues that need more info from the author label Aug 18, 2023
Copy link

github-actions bot commented May 7, 2024

It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment.
If you need further assistance or have questions, you can also search for similar issues on Stack Overflow.
Make sure to look at the README file for the most updated links.

@github-actions github-actions bot added the stale label May 7, 2024
@hamza1022
Copy link

Just change the node version to 21.7.3 it will resolve your issue.Thanks me later .....!

@github-actions github-actions bot removed the stale label Jun 1, 2024
@avivkeller avivkeller closed this as not planned Won't fix, can't repro, duplicate, stale Jun 10, 2024
@avivkeller
Copy link
Member

This issue didn't get a response to @gireeshpunathil's suggestion, and would've stale closed. If you disagree with this, please reopen :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info issues that need more info from the author question
Projects
None yet
Development

No branches or pull requests

5 participants