Unitech / Unitech/pm2

NextJS 13/14 app router fails with cluster mode with SIGINT

Open
#5,771 2 comments 1 reaction 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?

PM2 starts but immediately shows 'errored' status for all clusters.
I saw from community that I need to run by using 'next start' directly, but as I need to use .env files, I used env-cmd.
of course, I can run single instance by executing script manually from the command line

ecosystem.config.js

module.exports = {
    apps: [
        {
            name: 'mall-front',
            script: 'env-cmd -f .env.prd next start',
            instances: 3,
            exec_mode: 'cluster',
            merge_logs: true,
            autorestart: true,
            watch: false,
            // max_memory_restart: '1G',
            env: {
                NODE_ENV: 'dev',
            },
            env_prd: {
                NODE_ENV: 'prd',
            },
        },
    ],
};

result

PM2        | 2024-02-20T19:44:37: PM2 log: App [mall-front:1] exited with code [0] via signal [SIGINT]
PM2        | 2024-02-20T19:44:37: PM2 log: App [mall-front:1] starting in -cluster mode-
PM2        | 2024-02-20T19:44:37: PM2 log: App name:mall-front id:2 disconnected
PM2        | 2024-02-20T19:44:37: PM2 log: App [mall-front:2] exited with code [0] via signal [SIGINT]
PM2        | 2024-02-20T19:44:37: PM2 log: App [mall-front:2] starting in -cluster mode-
PM2        | 2024-02-20T19:44:37: PM2 log: App name:mall-front id:3 disconnected
PM2        | 2024-02-20T19:44:37: PM2 log: App [mall-front:3] exited with code [0] via signal [SIGINT]
PM2        | 2024-02-20T19:44:37: PM2 log: App [mall-front:3] starting in -cluster mode-
PM2        | 2024-02-20T19:44:37: PM2 log: App [mall-front:1] online
PM2        | 2024-02-20T19:44:37: PM2 log: App [mall-front:2] online
PM2        | 2024-02-20T19:44:37: PM2 log: App [mall-front:3] online
PM2        | 2024-02-20T19:44:37: PM2 log: App name:mall-front id:1 disconnected
PM2        | 2024-02-20T19:44:37: PM2 log: App [mall-front:1] exited with code [0] via signal [SIGINT]
PM2        | 2024-02-20T19:44:37: PM2 log: Script /bin/bash had too many unstable restarts (16). Stopped. "errored"
PM2        | 2024-02-20T19:44:37: PM2 log: App name:mall-front id:2 disconnected
PM2        | 2024-02-20T19:44:37: PM2 log: App [mall-front:2] exited with code [0] via signal [SIGINT]
PM2        | 2024-02-20T19:44:37: PM2 log: Script /bin/bash had too many unstable restarts (16). Stopped. "errored"
PM2        | 2024-02-20T19:44:37: PM2 log: App name:mall-front id:3 disconnected
PM2        | 2024-02-20T19:44:37: PM2 log: App [mall-front:3] exited with code [0] via signal [SIGINT]
PM2        | 2024-02-20T19:44:37: PM2 log: Script /bin/bash had too many unstable restarts (16). Stopped. "errored"

I can run with fork mode though, it causes lots of instances needed to run and maintain our service.

How could we reproduce this issue?

just run the script above

Supporting information

NextJS 14.1.0
NodeJS 18.18.2
PM2 5.3.0

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 failure using ecosystem.config.js with env-cmd -f .env.prd next start, three instances, and cluster mode, using the reported NextJS, NodeJS, and PM2 versions. Compare the cluster and fork results; done means the clustered app starts without SIGINT exits, disconnections, or unstable-restart errors.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.