Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v6.0.5 Cluster Mode not working with Bun #5963

Open
dienstbereit opened this issue Mar 16, 2025 · 6 comments
Open

v6.0.5 Cluster Mode not working with Bun #5963

dienstbereit opened this issue Mar 16, 2025 · 6 comments

Comments

@dienstbereit
Copy link

I’m experiencing an issue where PM2 version 6.0.5 does not seem to work in Cluster Mode with Bun, even though the release notes mention that Bun should be compatible with PM2 now.

  1. Create a simple Bun script (index.js):
const server = Bun.serve({
  port: 3000,
  fetch(req) {
    return new Response("Bun!");
  },
});
  1. Set up the PM2 ecosystem configuration (ecosystem.config.js):
module.exports = {
  name: "Cluster Test",
  script: "index.js",
  instances: "max",
  exec_mode: "cluster",
  watch: false,
};
  1. Start the application with PM2 using the configuration above.
  2. Check the PM2 logs.

Expected Behavior: The application should run in Cluster Mode, with instances of Bun being spawned as specified in the ecosystem.config.js file.

Actual Behavior: There are no errors in the PM2 logs, but the application does not seem to function as expected in Cluster Mode. The cluster instances are not being spawned, or the application is not responding properly.

Environment:
PM2 Version: 6.0.5
Bun Version: v1.2.5
Node.js Version: v23.6.0
OS: Linux Ubuntu x86_64 x86_64 x86_64 GNU/Linux

Additional Context:
PM2 does not show any error messages in the logs.
The issue only occurs in Cluster Mode, and switching to fork mode seems to work fine with Bun.

Image

@Unitech
Copy link
Owner

Unitech commented Mar 17, 2025

Thank you for this quality report.
I think that it's because PM2 use the node.js engine. To be able for the PM2 cluster to works it needs to be run with Bun.
Could you run a 'pm2 report' commands and tell me if it's the case ?

@dienstbereit
Copy link
Author

@Unitech thank you very much for your quick feedback. This report is from my local machine. I hope my setup is correct and I have not misunderstood something about the PM2/BUN concept 🤷‍♂️

--- PM2 report ----------------------------------------------------------------
Date                 : Mon Mar 17 2025 13:32:52 GMT+0100 (Central European Standard Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 6.0.5
node version         : 23.6.0
node path            : /opt/homebrew/bin/pm2
argv                 : /opt/homebrew/Cellar/node/23.6.0/bin/node,/opt/homebrew/lib/node_modules/pm2/lib/Daemon.js
argv0                : /opt/homebrew/Cellar/node/23.6.0/bin/node
user                 : user
uid                  : 501
gid                  : 20
uptime               : 124min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 6.0.5
node version         : 23.6.0
node path            : /opt/homebrew/bin/pm2
argv                 : /opt/homebrew/Cellar/node/23.6.0/bin/node,/opt/homebrew/bin/pm2,report
argv0                : node
user                 : user
uid                  : 501
gid                  : 20
===============================================================================
--- System info --------------------------------------------
arch                 : arm64
platform             : darwin
type                 : Darwin
cpus                 : Apple M4 Pro
cpus nb              : 14
freemem              : 327008256
totalmem             : 25769803776
home                 : /Users/user
===============================================================================
--- PM2 list -----------------------------------------------
┌────┬─────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name            │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├────┼─────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0  │ Cluster Test    │ default     │ 1.0.0   │ cluster │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ user     │ disabled │
│ 1  │ Cluster Test    │ default     │ 1.0.0   │ cluster │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ user     │ disabled │
│ 2  │ Cluster Test    │ default     │ 1.0.0   │ cluster │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ user     │ disabled │
│ 3  │ Cluster Test    │ default     │ 1.0.0   │ cluster │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ user     │ disabled │
│ 4  │ Cluster Test    │ default     │ 1.0.0   │ cluster │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ user     │ disabled │
│ 5  │ Cluster Test    │ default     │ 1.0.0   │ cluster │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ user     │ disabled │
│ 6  │ Cluster Test    │ default     │ 1.0.0   │ cluster │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ user     │ disabled │
│ 7  │ Cluster Test    │ default     │ 1.0.0   │ cluster │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ user    │ disabled │
│ 8  │ Cluster Test    │ default     │ 1.0.0   │ cluster │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ user     │ disabled │
│ 9  │ Cluster Test    │ default     │ 1.0.0   │ cluster │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ user     │ disabled │
│ 10 │ Cluster Test    │ default     │ 1.0.0   │ cluster │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ user     │ disabled │
│ 11 │ Cluster Test    │ default     │ 1.0.0   │ cluster │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ user     │ disabled │
│ 12 │ Cluster Test    │ default     │ 1.0.0   │ cluster │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ user     │ disabled │
│ 13 │ Cluster Test    │ default     │ 1.0.0   │ cluster │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ user     │ disabled │
└────┴─────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/Users/user/.pm2/pm2.log last 20 lines:
PM2        | 2025-03-17T13:32:49: PM2 log: App [Cluster Test:11] exited with code [0] via signal [SIGINT]
PM2        | 2025-03-17T13:32:49: PM2 log: Script /Users/user/Sites/localhost/pm2-bun-cluster-test/index.js had too many unstable restarts (16). Stopped. "errored"
PM2        | 2025-03-17T13:32:49: PM2 log: App name:Cluster Test id:9 disconnected
PM2        | 2025-03-17T13:32:49: PM2 log: App [Cluster Test:9] exited with code [0] via signal [SIGINT]
PM2        | 2025-03-17T13:32:49: PM2 log: App [Cluster Test:9] starting in -cluster mode-
PM2        | 2025-03-17T13:32:49: PM2 log: App [Cluster Test:10] online
PM2        | 2025-03-17T13:32:49: PM2 log: App name:Cluster Test id:13 disconnected
PM2        | 2025-03-17T13:32:49: PM2 log: App [Cluster Test:13] exited with code [0] via signal [SIGINT]
PM2        | 2025-03-17T13:32:49: PM2 log: Script /Users/user/Sites/localhost/pm2-bun-cluster-test/index.js had too many unstable restarts (16). Stopped. "errored"
PM2        | 2025-03-17T13:32:49: PM2 log: App [Cluster Test:12] online
PM2        | 2025-03-17T13:32:49: PM2 log: App [Cluster Test:9] online
PM2        | 2025-03-17T13:32:49: PM2 log: App name:Cluster Test id:10 disconnected
PM2        | 2025-03-17T13:32:49: PM2 log: App [Cluster Test:10] exited with code [0] via signal [SIGINT]
PM2        | 2025-03-17T13:32:49: PM2 log: Script /Users/user/Sites/localhost/pm2-bun-cluster-test/index.js had too many unstable restarts (16). Stopped. "errored"
PM2        | 2025-03-17T13:32:49: PM2 log: App name:Cluster Test id:12 disconnected
PM2        | 2025-03-17T13:32:49: PM2 log: App [Cluster Test:12] exited with code [0] via signal [SIGINT]
PM2        | 2025-03-17T13:32:49: PM2 log: Script /Users/user/Sites/localhost/pm2-bun-cluster-test/index.js had too many unstable restarts (16). Stopped. "errored"
PM2        | 2025-03-17T13:32:49: PM2 log: App name:Cluster Test id:9 disconnected
PM2        | 2025-03-17T13:32:49: PM2 log: App [Cluster Test:9] exited with code [0] via signal [SIGINT]
PM2        | 2025-03-17T13:32:49: PM2 log: Script /Users/user/Sites/localhost/pm2-bun-cluster-test/index.js had too many unstable restarts (16). Stopped. "errored"

@dienstbereit
Copy link
Author

Could you run a 'pm2 report' commands and tell me if it's the case ?

@Unitech have you been able to take a closer look at the problem? Or is the problem with my implementation?

@Unitech
Copy link
Owner

Unitech commented Apr 1, 2025

Yes this is caused by https://github.com/Unitech/pm2/blob/master/bin/pm2#L1
The shebang calls node, and in my knowledge, there is currently no way in bash, while keeping windows support to call bun instead of node.
I will create a specific pm2 "binary" that will call Bun instead

@Kuuzoo
Copy link

Kuuzoo commented Apr 1, 2025

Hi there, from what I know you can force shebang forced apps to be called with bun using the --bun param.
So for example, bunx --bun pm2 start should work here.

@Kuuzoo
Copy link

Kuuzoo commented Apr 1, 2025

Also, I've just tried to run your exact script using bun v1.2.8 on the a mac with the same cores and chip without any troubles.

By using either of the following commands: bunx --bun pm2 start & pm2 start (pm2 globally installed via bun).

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants