Pm2: NODE_APP_INSTANCE always 0 since 2.5.0

Created on 28 Jun 2017  ยท  7Comments  ยท  Source: Unitech/pm2

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.

Supporting information

Node version: v8.1.2
Linux
Pending Release Daemon Bug

Most helpful comment

I reproduced the problem, trying to find a fix

All 7 comments

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.

  1. Clone it
  2. Edit paths in start.json
  3. Install [email protected]
  4. Start the app with pm2 start start.json and watch log output. It should all be fine. 4 instances running on ports 9990 to 9993
  5. Delete the app (pm2 delete pm2-issue-2984)
  6. Install latest pm2 && pm2 update && pm2 flush
  7. Start app again. Now it should flood the log with errors because NODE_APP_INSTANCE is 0 in every instance and therefore node tries to use the same port for multiple hapi server instances.

I tried to capture the process in a video. Maybe this helps too?

pm2-issue-2984.zip

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jubairsaidi picture jubairsaidi  ยท  3Comments

psparago picture psparago  ยท  3Comments

waygee picture waygee  ยท  4Comments

getvega picture getvega  ยท  3Comments

morfies picture morfies  ยท  3Comments