v6.0.5 Cluster Mode not working with Bun
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.
- Create a simple Bun script (
index.js):
const server = Bun.serve({
port: 3000,
fetch(req) {
return new Response("Bun!");
},
});
- Set up the PM2 ecosystem configuration (
ecosystem.config.js):
module.exports = {
name: "Cluster Test",
script: "index.js",
instances: "max",
exec_mode: "cluster",
watch: false,
};
- Start the application with PM2 using the configuration above.
- 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.
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 ?
@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"
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?
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
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.
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).
unfortunately upgrading to v6 didn't work for me. bunx --bun or just bun yield the same result:
module.exports = {
apps: [
{
name: `myapp`,
interpreter: "~/.bun/bin/bun",
script: "server/index.ts",
instances: "4",
watch: false,
exec_mode: "cluster",
env: {
NODE_ENV: "production",
},
},
],
};
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /home/ec2-user/myapp/server/index.ts
@Unitech any luck with the bun specific binary?
I use command bun x pm2 to run. Try this.
@adarshmadrecha what's your pm2 config?