pm2
pm2 copied to clipboard
Cluster mode does not work on node v16
What's going wrong?
When the application runs in cluster mode, only one cluster is "online" and the other is "error" or "launching" all the time.
Error on node v16.14.0 and pm2 v5.1.2, if I downgrade node to v14.19.0 all cluster are "online"
How could we reproduce this issue?
- Install
n 16.14.0
andnpm install pm2@latest -g
andpm2 update
- Make simple node app, I did this https://www.tutorialspoint.com/nodejs/nodejs_first_application.htm
- Make npm init
- Make for ex. pm2.json
{
"apps": [
{
"name": "node_app_test",
"script": "npm",
"args": "run start",
"instances": 2,
"exec_mode": "cluster",
"wait_ready": true
}
]
}
-
pm2 start pm2.json
And will be "launching" see PM2 report below if u wanna run without error: -
n 14.19.0
andnpm install pm2@latest -g
andpm2 update
- run
pm2 start pm2.json
And all clouser will be "online"
--- PM2 list -----------------------------------------------
┌─────┬──────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼──────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ node_app_test │ default │ N/A │ cluster │ 3616 │ 12s │ 0 │ online │ 1.9% │ 47.9mb │ deploy │ disabled │
│ 1 │ node_app_test │ default │ N/A │ cluster │ 3636 │ 9s │ 0 │ online │ 0.2% │ 56.2mb │ deploy │ disabled │
└─────┴──────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
Supporting information
--- PM2 report ----------------------------------------------------------------
Date : Fri Feb 11 2022 10:23:12 GMT+0100 (Central European Standard Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 5.1.2
node version : 16.14.0
node path : /usr/local/bin/pm2
argv : /usr/local/bin/node,/usr/local/lib/node_modules/pm2/lib/Daemon.js
argv0 : node
user : deploy
uid : 1001
gid : 1001
uptime : 51min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 5.1.2
node version : 16.14.0
node path : /usr/local/bin/pm2
argv : /usr/local/bin/node,/usr/local/bin/pm2,report
argv0 : node
user : deploy
uid : 1001
gid : 1001
===============================================================================
--- System info --------------------------------------------
arch : x64
platform : linux
type : Linux
cpus : DO-Regular
cpus nb : 2
freemem : 2573303808
totalmem : 4138557440
home : /home/deploy
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬──────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼──────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ node_app_test │ default │ N/A │ cluster │ 14660 │ 8s │ 0 │ online │ 1.5% │ 56.4mb │ deploy │ disabled │
│ 1 │ node_app_test │ default │ N/A │ cluster │ 14919 │ 0 │ 10 │ launching │ 0% │ 0b │ deploy │ disabled │
└─────┴──────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/home/deploy/.pm2/pm2.log last 20 lines:
PM2 | at Server.listen (node:net:1465:7)
PM2 | at Object.<anonymous> (/home/deploy/node_test/index.js:11:4)
PM2 | at Module._compile (node:internal/modules/cjs/loader:1103:14)
PM2 | at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
PM2 | at Module.load (node:internal/modules/cjs/loader:981:32)
PM2 | at Function.Module._load (node:internal/modules/cjs/loader:822:12)
PM2 | at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
PM2 | at node:internal/main/run_main_module:17:47
PM2 | Emitted 'error' event on Server instance at:
PM2 | at emitErrorNT (node:net:1357:8)
PM2 | at processTicksAndRejections (node:internal/process/task_queues:83:21) {
PM2 | code: 'EADDRINUSE',
PM2 | errno: -98,
PM2 | syscall: 'listen',
PM2 | address: '::',
PM2 | port: 8088
PM2 | }
PM2 | 2022-02-11T10:23:11: PM2 log: App name:node_app_test id:1 disconnected
PM2 | 2022-02-11T10:23:11: PM2 log: App [node_app_test:1] exited with code [1] via signal [SIGINT]
PM2 | 2022-02-11T10:23:11: PM2 log: App [node_app_test:1] starting in -cluster mode-
same issue with node v16.14.0 and pm2 v5.1.2. The firs instance run but all the rest stuck on launch.
confirmed also on node v14.15 with pm2 v5.2.0
I even tried to add it as cluster_mode
For me it works with node v16 and above (didn't try lower) if I use the application declaration (config js file, on mac) although it seems to fail the number of declared instances (if I don't delete the "app" first, maybe it is just the expected).
If it doesn't work try editing the generated file after pm2 init simple
https://pm2.keymetrics.io/docs/usage/application-declaration/
P.S.: on Windows node v16.13.1 it worked fine without a config file.
Same issue with node v18.13.0 and pm2 5.2.2. This seems to be an issue "npm run start"
So, if I'm understanding correctly, if you have exec_mode: cluster_mode
, then you can only run on Node v14?
Same issue here
same issue with node v20.9.0, pm2 v5.3.0 on next js v13.5.6
same issue
Same issue on Node.js v20.11.1 and Next.js 14.1.4.
npm just returns "Error: command failed" without any further details. It works fine without cluster mode.
It is problem with "npm run start", so if you wanna run cluster mode use:
...
"script": "node_modules/next/dist/bin/next",
"args": "start",
"exec_mode": "cluster"
...
"script": "node_modules/next/dist/bin/next", "args": "start",
@pawelmidur Thanx you! That works for me!