Pm2 mode cluster project Next 14 infinite reload

25 views Asked by At

I have a Next 14 project running on PM2 in cluster mode, my VPS has 4 vCPUs, when starting only one process is stable while the other three processes are in infinite reload. Below is my ecosystem.config.js configuration file.

module.exports = {
  apps: [
    {
      name: "application",
      script: "npm",
      exec_mode: "cluster",
      instances: "max",
      args: "start",
      env: {
        NODE_ENV: "production",
        PORT: 5000
      },
    },
  ],
};

pm2 version: 5.3.1

enter image description here

enter image description here

In the last image the three clusters restarted 24 times

I used max_memory_restart even though the problem continues, the VPS has 6GB of RAM.

pm2 logs

PM2      | App [application:3] online
0|application  | > [email protected] start
0|application  | > next start
PM2            | App name:application id:1 disconnected
PM2            | App [application:1] exited with code [1] via signal [SIGINT]
PM2            | App [application:1] starting in -cluster mode-
PM2            | App [application:1] online
PM2            | App name:application id:0 disconnected
PM2            | App [application:0] exited with code [1] via signal [SIGINT]
PM2            | App [application:0] starting in -cluster mode-
PM2            | App [application:0] online
3|application  | > [email protected] start
3|application  | > next start
1|application  | > [email protected] start
1|application  | > next start
PM2            | App name:application id:3 disconnected
PM2            | App [application:3] exited with code [1] via signal [SIGINT]
PM2            | App [application:3] starting in -cluster mode-
PM2            | App [application:3] online
0|application  | > [email protected] start
0|application  | > next start
PM2            | App name:application id:1 disconnected
PM2            | App [application:1] exited with code [1] via signal [SIGINT]
PM2            | App [application:1] starting in -cluster mode-
PM2            | App [application:1] online
PM2            | App name:application id:0 disconnected
PM2            | App [application:0] exited with code [1] via signal [SIGINT]
PM2            | App [application:0] starting in -cluster mode-
PM2            | App [application:0] online
3|application  | > [email protected] start
3|application  | > next start
1|application  | > [email protected] start
1|application  | > next start
PM2            | App name:application id:3 disconnected
PM2            | App [application:3] exited with code [1] via signal [SIGINT]
PM2            | App [application:3] starting in -cluster mode-
PM2            | App [application:3] online

1

There are 1 answers

0
Rafael Junio On

SOLUTION:

module.exports = {
  apps: [
    {
      name: "application",
      script: "./node_modules/next/dist/bin/next", // changed
      exec_mode: "cluster",
      instances: "max",
      args: "start",
      env: {
        NODE_ENV: "production",
        PORT: 5000
      },
    },
  ],
};