Skip to content

Understanding Memory Allocation + Debug memory Leak #4200

Closed as not planned
Closed as not planned
@XciD

Description

@XciD

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions