Skip to content

Node v12.16.2 memory issues after upgrade from v8 (<--- Last few GCs --->) #33266

@RobertDittmann

Description

@RobertDittmann

This issue is continuation of #32737

Version:
v12.16.2 (but v12.13 on production)

Platform:
Darwin Kernel Version 19.4.0: Wed Mar 4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64 x86_64
(but docker with node:12.13.0-alpine on production)

Subsystem:
? runtime, heap, garbage collection

Description:
As in previous ticket: "We recently upgrade our production servers with docker containers with node v8 to docker containers with node v12.10 (node:12.13.0-alpine). At first all seems fine, but then we started noticing pod restarts by Kubernetes being OOM Killed. Since the upgrade, memory usage seems to increase over time sometimes in steep inclines until reaching ~500MB at which time they are killed by Kuberenetes."

With the same code base and dependencies, when switching between 3 versions of node (8.17.0, 10.20.1, 12.16.2) different memory usage observed. With version 12.16.2 node service crashes with logs:

TESTED_SERVICE.GetData took 1691 ms (queue-time = 409 ms, process-time = 1282 ms, processing-count = 100, queue-size = 124)"}
{"@timestamp":"2020-05-06T10:49:42.337Z","level":"debug","message":"GRPC server call TESTED_SERVICE.GetData took 1724 ms (queue-time = 431 ms, process-time = 1293 ms, processing-count = 100, queue-size = 123)"}

<--- Last few GCs --->
cr[35106:0x102aac000] 10407728 ms: Mark-sweep 543.8 (546.1) -> 543.7 (546.1) MB, 158.9 / 0.0 ms  (+ 2.9 ms in 2 steps since start of marking, biggest step 2.9 ms, walltime since start of marking 163 ms) (average mu = 0.102, current mu = 0.010) finalize incr[35106:0x102aac000] 10407914 ms: Mark-sweep 543.8 (546.1) -> 543.7 (546.1) MB, 177.3 / 0.0 ms  (+ 5.1 ms in 2 steps since start of marking, biggest step 5.0 ms, walltime since start of marking 186 ms) (average mu = 0.058, current mu = 0.018) finalize incr

<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 0x10097d5b9]
    1: StubFrame [pc: 0x1009e8f05]
Security context: 0x1fc1cc0c08d1 <JSObject>
    2: new constructor(aka Op) [0x1fc1b415e939] [/Users/robertdittmann/Documents/Tutorials/node-memory-test/node_modules/protobufjs/src/writer.js:21] [bytecode=0x1fc1cf4764f1 offset=0](this=0x1fc1ca0d2b61 <Op map = 0x1fc11cbd1199>,0x1fc1b415e979 <JSFunction noop (sfi = 0x1fc1712aee81)>,0,0)
    3: ConstructFrame [pc: 0x1008fe7...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x1010248bd node::Abort() (.cold.1) [/usr/local/bin/node]
 2: 0x100084c4d node::FatalError(char const*, char const*) [/usr/local/bin/node]
 3: 0x100084d8e node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
 4: 0x100186477 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 5: 0x100186417 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 6: 0x1003141c5 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
 7: 0x100315a3a v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [/usr/local/bin/node]
 8: 0x10031246c v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
 9: 0x10031026e v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
10: 0x10030f2b1 v8::internal::Heap::HandleGCRequest() [/usr/local/bin/node]
11: 0x1002d4551 v8::internal::StackGuard::HandleInterrupts() [/usr/local/bin/node]
12: 0x10063e79c v8::internal::Runtime_StackGuard(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
13: 0x10097d5b9 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]
14: 0x1009e8f05 Builtins_StackCheckHandler [/usr/local/bin/node]
[1]    35106 abort      node --max-old-space-size=384 app.js

What steps will reproduce the bug?

  1. Download prepared sample "slim version" of service code (without other parts like Redis, DynamoDB, Prometheus, Zippkin, Routes etc.): node-sample
  2. Download prepared sample client: java-sample
  3. Change node version on 12.16.2
  4. For node service (rebuild and run):
rm -rf node-modules
npm install
node --max-old-space-size=384 app.js
  1. For java service (rebuild and run):
mvn clean install
mvn spring-boot:run
  1. After around 3-4 hours node service should throws above exception. Node service in its directory will fill with data csv file called memory_usage.csv (it contains process memory in MB per 1 minute).

Same situation appears on production environment but it takes few days to happen.

Below comparison of node vesions:

  • node v12.16.2 started with command: node --max-old-space-size=384 app.js (crashed - results as above logs)
    image

  • node v12.16.2 started with command: node app.js
    image

  • node v10.20.1 started with command: node app.js (it shows also memory when load stopped)
    image

  • node v8.17.0 started with command: node app.js
    image

How often does it reproduce? Is there a required condition?
Always.

What is the expected behavior?
A stable heapUsed like in v8.17 and no spikes in memory usage causing OOM kills/ GCs issues.

What do you see instead?
Memory increase and GCs issues.

Additional information
I am looking for solutions. Seems that used last years services cannot be used with LTS v12 on production.

Please let me know how I can help further,

Kind regards,
Robert

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.memoryIssues and PRs related to the memory management or memory footprint.v8 engineIssues and PRs related to the V8 dependency.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions