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

Error cause is not displayed when PM2 is started in cluster mode #5811

Open
OliverJAsh opened this issue Apr 30, 2024 · 0 comments
Open

Error cause is not displayed when PM2 is started in cluster mode #5811

OliverJAsh opened this issue Apr 30, 2024 · 0 comments

Comments

@OliverJAsh
Copy link

OliverJAsh commented Apr 30, 2024

What's going wrong?

Error cause is not displayed when PM2 is started in cluster mode.

How could we reproduce this issue?

package.json:

{
  "dependencies": {
    "pm2": "^5.3.1"
  }
}

server.js:

throw new Error("foo", {
  cause: new Error("bar"),
});
$ yarn run pm2-runtime --instances 1 server.js
yarn run v1.22.22
warning package.json: No license field
$ /Users/oliver/Code/reduced-test-cases/pm2-error-cause/node_modules/.bin/pm2-runtime --instances 1 server.js
2024-04-30T19:35:48: PM2 log: Launching in no daemon mode
2024-04-30T19:35:48: PM2 log: App [server:0] starting in -cluster mode-
2024-04-30T19:35:48: PM2 log: App [server:0] online
Error: foo
    at Object.<anonymous> (/Users/oliver/Code/reduced-test-cases/pm2-error-cause/server.js:1:7)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
    at Module.load (node:internal/modules/cjs/loader:1206:32)
    at Module._load (node:internal/modules/cjs/loader:1022:12)
    at /Users/oliver/Code/reduced-test-cases/pm2-error-cause/node_modules/pm2/lib/ProcessContainer.js:304:25
    at wrapper (/Users/oliver/Code/reduced-test-cases/pm2-error-cause/node_modules/pm2/node_modules/async/internal/once.js:12:16)
    at next (/Users/oliver/Code/reduced-test-cases/pm2-error-cause/node_modules/pm2/node_modules/async/waterfall.js:96:20)
    at /Users/oliver/Code/reduced-test-cases/pm2-error-cause/node_modules/pm2/node_modules/async/internal/onlyOnce.js:12:16
    at /Users/oliver/Code/reduced-test-cases/pm2-error-cause/node_modules/pm2/lib/Utility.js:175:18
2024-04-30T19:35:48: PM2 log: App name:server id:0 disconnected
2024-04-30T19:35:48: PM2 log: App [server:0] exited with code [0] via signal [SIGINT]

If we remove --instances 1, PM2 will start in fork mode instead of cluster mode. There the issue does not reproduce:

$ yarn run pm2-runtime server.js
yarn run v1.22.22
warning package.json: No license field
$ /Users/oliver/Code/reduced-test-cases/pm2-error-cause/node_modules/.bin/pm2-runtime server.js
2024-04-30T19:36:22: PM2 log: Launching in no daemon mode
2024-04-30T19:36:22: PM2 log: App [server:0] starting in -fork mode-
2024-04-30T19:36:22: PM2 log: App [server:0] online
Error: foo
    at Object.<anonymous> (/Users/oliver/Code/reduced-test-cases/pm2-error-cause/server.js:1:7)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    ... 7 lines matching cause stack trace ...
    at Module._load (node:internal/modules/cjs/loader:1022:12) {
  [cause]: Error: bar
      at Object.<anonymous> (/Users/oliver/Code/reduced-test-cases/pm2-error-cause/server.js:2:10)
      at Module._compile (node:internal/modules/cjs/loader:1369:14)
      at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
      at Module.load (node:internal/modules/cjs/loader:1206:32)
      at Module._load (node:internal/modules/cjs/loader:1022:12)
      at Object.<anonymous> (/Users/oliver/Code/reduced-test-cases/pm2-error-cause/node_modules/pm2/lib/ProcessContainerFork.js:33:23)
      at Module._compile (node:internal/modules/cjs/loader:1369:14)
      at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
      at Module.load (node:internal/modules/cjs/loader:1206:32)
      at Module._load (node:internal/modules/cjs/loader:1022:12)
}
2024-04-30T19:36:22: PM2 log: App [server:0] exited with code [1] via signal [SIGINT]
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

1 participant