nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
106.76k stars 29.14k forks source link

Non-heap memory leak in node:10.15.3-alpine, node:10.16.0-alpine #29038

Open mgartner opened 5 years ago

mgartner commented 5 years ago

Copied from https://github.com/nodejs/docker-node/issues/1082

We've witnessed a consistent memory leak in 2 versions of the node alpine Docker images: node:10.15.3-alpine and node:10.16.0-alpine. This leak may be present in other versions of the alpine images, but we know it is NOT present in node:6.11.1-alpine, node:8.16.0-alpine, node:10.15.3-jessie, and node:10.15.3-stretch.

This leak is a non-heap leak—the Node heap is not consistently growing, but the memory used by the docker container is.

Here is are some graphs demonstrating the leak across ~20 containers. The blue lines are the RSS of the docker containers and the red lines are the size of the Node heaps of the processes within each container.

node:10.15.3-alpine

node-10-15-3-alpine

node:10.16.0-alpine

node-10-16-0-alpine

node:10.15.3-stretch (no leak, for reference)

node-10-15-3-stretch

ronag commented 5 years ago

Do you think you could figure out which version introduced this behaviour?

ChALkeR commented 5 years ago

@mgartner It would help if there was either a consistent way to reproduce this, or if the change was nailed down to a more specific version range than v8.16.0...v10.15.3. Another possible way forward: perhaps you could launch node with valgrind --tool=massif node to generate memory profiles? (Note: that will consume more memory).

ghost commented 4 years ago

we noticed the same using alpine-node:10.1 therefore we switched to node:10.1-stretch and you can notice the difference.

The docker image alpine-node:10.1 have been used till 8th of October.

docker_memory

chaffeqa commented 4 years ago

was this ever resolved?

mohammedpatla commented 1 week ago

I have noticed a similar issue in node:20.17.0 usually the heap goes to 2-3gigs and clears out but the RSS keeps on jumping up until there is no resources and then crashes. I have an app with nestjs + prisma that has a lot of async db requests that might be taking up memory are DB calls via axios or apollo.

Anyway, in Alpine, my app straight-up crashes, so I moved to Bullseye. At least when the app reaches its maximum usage limit, the garbage collector kicks in and clears a lot of RSS, but not frequently enough—just enough that our app does not crash too frequently.