Unitech / Unitech/pm2

Cluster mode does not work on node v16

Open
#5,300 11 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

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?

  1. Install n 16.14.0 and npm install pm2@latest -g and pm2 update
  2. Make simple node app, I did this https://www.tutorialspoint.com/nodejs/nodejs_first_application.htm
  3. Make npm init
  4. Make for ex. pm2.json
{
  "apps": [
    {
      "name": "node_app_test",
      "script": "npm",
      "args": "run start",
      "instances": 2,
      "exec_mode": "cluster",
      "wait_ready": true
    }
  ]
}
  1. pm2 start pm2.json
    And will be "launching" see PM2 report below
    if u wanna run without error:
  2. n 14.19.0 and npm install pm2@latest -g and pm2 update
  3. 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-

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the provided pm2.json and simple index.js app on Node.js 16.14.0 and PM2 5.1.2, then start with the PM2 daemon log showing EADDRINUSE and the cluster worker lifecycle. Done means both configured cluster instances remain online on Node.js 16 without repeated launches or port errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.