0

I am trying to deploy a Next.js(next@12.0.8) application on a production Linux server, Daemonize and load-balance it via pm2 npm module.

When I start the application in fork mode all works fine.

The problem arises when I start it in a cluster mode with 4 instances. In this case only one instance is running and the rest of the instances are with "status=errored".

Node.js version = v16.13.2

Next.js version = 12.0.8

pm2 version = 5.1.2

and here is the ecosystem.config.js :

module.exports = {
  apps : [{
    name   : "csr-next",
    cwd: '/home/ruby/node/next-gen/',
    script: 'npm',
    args: 'start',
    exec_mode : "cluster",
    instances: 4
  }],
};

Here is a demo video to demonstrate.

Checked the CPU(s) number on the host machine via $lscpu

CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              4
On-line CPU(s) list: 0-3
Thread(s) per core:  2
Core(s) per socket:  2
Hairi
  • 3,318
  • 2
  • 29
  • 68
  • I saw in your video that the first (`0`) app always works as intended and, `1, 2, and 3` are the ones that give you issues. Have you checked to see how Next.js handles port bindings? This might help as well: https://github.com/Unitech/PM2/issues/1510#issuecomment-131145772 – Salvador Hernandez Feb 09 '22 at 09:36
  • This might also help: https://github.com/vercel/next.js/discussions/10675#discussioncomment-590 – Salvador Hernandez Feb 09 '22 at 09:39

0 Answers0