What's going wrong?
It seems that since 2.5.0 every instance has NODE_APP_INSTANCE set to 0.
How could we reproduce this issue?
Start an app in fork mode with two instances and output NODE_APP_INSTANCE. It should always be 0.
As soon as I downgraded to 2.4.4 it started working again.
Node version: v8.1.2
Linux
I tried using the cluster and fork modes,
The cluster mode is working properly
Fork mode will appear NODE_APP_INSTANCE has been 0 case
I'm not able to reproduce the problem with the test suites, could you explain how you start your application ?
@vmarchaud
My configuration file is as follows
{
"apps": [
{
"name" : "sms.x",
"max_memory_restart": "1024M",
"log_date_format": "YYYY-MM-DD HH:mm:ss SSS",
"script": "./app.js",
"out_file": "./log/sms/app.log",
"error_file": "./log/sms/err.log",
"instances" : 2,
"exec_mode" : "fork",
"env": {
"isMaster": "0",
"CDN_PREFIX": "//dbde4sd21oahf.cloudfront.net",
"MONGO_URL": "mongodb://localhost:27017/rocketchat",
"MONGO_OPLOG_URL": "mongodb://localhost:27017/local",
"ROOT_URL": "http://rocket.chat",
"PORT": "4000"
}
}
]
}
In version 2.4.6 is normal, you can get two NODE_APP_INSTANCE, 0 and 1
However, in version 2.5.0, NODE_APP_INSTANCE is 0
Sure. I put up a repo with sample code to reproduce the problem.
https://github.com/pkaske/pm2-issue-2984
It a very basic hapijs server (copy pasted from the tutorial). Only difference really is that NODE_APP_INSTANCE is used to increment the port for the server instances.
pm2 start start.json and watch log output. It should all be fine. 4 instances running on ports 9990 to 9993pm2 delete pm2-issue-2984)I tried to capture the process in a video. Maybe this helps too?
I reproduced the problem, trying to find a fix
Published on PM2 2.6.0:
$ npm install pm2@latest -g
$ pm2 update
The issue came back for me in the 4.2.3, @Unitech
Inside docker that restarts on any code changes, never used scaling, always 3 instances
--- PM2 report ----------------------------------------------------------------
Date : Thu Apr 23 2020 11:50:14 GMT+0000 (Coordinated Universal Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 4.2.3
node version : 12.16.1
node path : not found
argv : /usr/bin/node,/usr/bin/pm2,start,--no-daemon,--node-args=--max-old-space-size=4056,-i,3,app/index.js
argv0 : node
user : undefined
uid : 0
gid : 0
uptime : 3min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 4.2.3
node version : 12.16.1
node path : not found
argv : /usr/bin/node,/usr/bin/pm2,report
argv0 : node
user : undefined
uid : 0
gid : 0
===============================================================================
--- System info --------------------------------------------
arch : x64
platform : linux
type : Linux
cpus : Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz
cpus nb : 4
freemem : 9898024960
totalmem : 16624889856
home : /root
===============================================================================
--- PM2 list -----------------------------------------------
โโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโฌโโโโโโโฌโโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโ
โ id โ name โ namespace โ version โ mode โ pid โ uptime โ โบ โ status โ cpu โ mem โ user โ watching โ
โโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโผโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโค
โ 0 โ index โ default โ 1.0.0 โ cluster โ 16 โ 3m โ 0 โ online โ 0.4% โ 152.3mb โ root โ disabled โ
โ 1 โ index โ default โ 1.0.0 โ cluster โ 23 โ 3m โ 0 โ online โ 0.3% โ 152.1mb โ root โ disabled โ
โ 2 โ index โ default โ 1.0.0 โ cluster โ 30 โ 3m โ 0 โ online โ 0.3% โ 152.8mb โ root โ disabled โ
โโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโดโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโ
===============================================================================
--- Daemon logs --------------------------------------------
All three instances have NODE_APP_INSTANCE equal to 0
Most helpful comment
I reproduced the problem, trying to find a fix