Memory of server is slowly increasing and I got out of memory.
Iโve been debugging my server in chrome, the memory periodically keeps objects that seems to histogram every 0.5 ~ 1 second. According to this document, it is supposed to keep datas only last 5 minutes by default, but continuous keep holding objects and slowly increase the memory. Iโve tried turn this metric off, it is default function in pm2 I guess. Pm2 needs extra function to turn metrics off or control period
Just run server with pm2 and debugging with chrome devtool

--- Daemon -------------------------------------------------
pm2d version : 3.2.9
node version : 10.15.0
node path : not found
argv : /usr/local/bin/node,/usr/local/bin/pm2-runtime,start,echosystem.config.js,--env,production
argv0 : node
user : user
uid : 1001
gid : 1001
uptime : 958min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 3.2.9
node version : 10.15.0
node path : /usr/local/bin/pm2
argv : /usr/local/bin/node,/usr/local/bin/pm2,report
argv0 : node
user : user
uid : 1001
gid : 1001
===============================================================================
--- System info --------------------------------------------
arch : x64
platform : linux
type : Linux
cpus : Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz
cpus nb : 2
freemem : 68087808
totalmem : 1004294144
home : /home/user
===============================================================================
Hi,
We reproduced it too, all our micro services on prod have memory leak too since 3.5.1.
Moreover, there is no package.lock file on this repo so we cannot go back to 3.5.0 to as a working version.
We managed to compare 3.5.1 & 3.5.0 and we can see the memory leak is not coming from the pm2 repo code but from 3rd party code.
This is the diff in dependencies:

looks like there was a problem with pm2/[email protected] which fixed on 4.2.2
see https://github.com/keymetrics/pm2-io-apm/issues/252
we verified it on prod and looks like problem solved!
Great! Closing now
Great! Closing now
I think you must have package.lock file in order to prevent this kind of issues in the future.
Thanks
@shimiml4 I also got memory leak when use PM2 in 3.5.1๏ผnow I downgrade to 3.4.1 which is fine in these days.
Same here using version 3.5.1.
With node memory is restored after a image resize process, with pm2 the memory usage still to max after the request finished.
I'm using node 10.16.3 and process to resize images is using https://github.com/lovell/sharp
'use strict';
const sharp = require('sharp');
module.exports = class extends require('./interface') {
static image(source, target, config) {
return sharp(source)
.resize(config.width, config.height, config.options)
.jpeg(config.quality)
.toFile(target);
}
}
source is a file route string. The memory increase on every file processed and never is released.
After 2.000 images processed, memory is 3.8G.
$ pm2 list
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโฌโโโโโโโโโโฌโโโโโโโฌโโโโโโโโโฌโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโฌโโโโโโโฌโโโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโ
โ App name โ id โ version โ mode โ pid โ status โ restart โ uptime โ cpu โ mem โ user โ watching โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโผโโโโโโโโโโผโโโโโโโผโโโโโโโโโผโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโผโโโโโโโผโโโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโค
โ XXXXXXXXXXXXXXXXXXXXXXXXXX โ 13 โ 0.0.1 โ fork โ 68707 โ online โ 2 โ 31m โ 0.3% โ 3.8 GB โ www-data โ disabled โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโดโโโโโโโโโโดโโโโโโโดโโโโโโโโโดโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโดโโโโโโโดโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโ
I need to restart pm2 on every image resize batch process.
As @eminoda say, downgrading to 3.4.1 solves the problem.
no its not solve the problem.
Any updates ?
Is this still an issue for anyone on v 3.5.1?
Most helpful comment
Any updates ?