NextJS 13/14 app router fails with cluster mode with SIGINT
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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