Custom handler not executed when there is an error inside a async function.
Open
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?
Custom handler not executed when there is an error inside a async function.
How could we reproduce this issue?
Create a file named test.js with the following content:
process.on("uncaughtException", e => {
console.log("====== CUSTOM HANDLER EXECUTED ======");
});
(async () => {
throw new Error("Test Error");
})();
This command works as expected (the custom handler is executed).
node test.js
This doesn't:
pm2 start test.js --attach
Supporting information
--- PM2 report ----------------------------------------------------------------
Date : Sun Nov 13 2022 12:52:00 GMT-0300 (Brasilia Standard Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 5.2.0
node version : 16.16.0
node path : /Users/danilo/.nvm/versions/node/v16.16.0/bin/pm2
argv : /Users/danilo/.nvm/versions/node/v16.16.0/bin/node,/Users/danilo/.nvm/versions/node/v16.16.0/lib/node_modules/pm2/lib/Daemon.js
argv0 : node
user : root
uid : 0
gid : 0
uptime : 0min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 5.2.0
node version : 16.16.0
node path : /Users/danilo/.nvm/versions/node/v16.16.0/bin/pm2
argv : /Users/danilo/.nvm/versions/node/v16.16.0/bin/node,/Users/danilo/.nvm/versions/node/v16.16.0/bin/pm2,report
argv0 : node
user : root
uid : 0
gid : 0
===============================================================================
--- System info --------------------------------------------
arch : arm64
platform : darwin
type : Darwin
cpus : Apple M1
cpus nb : 8
freemem : 70975488
totalmem : 8589934592
home : /var/root
===============================================================================
--- PM2 list -----------------------------------------------
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0 │ test │ fork │ 0 │ online │ 0.7% │ 39.6mb │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/var/root/.pm2/pm2.log last 20 lines:
PM2 | 2022-11-13T12:51:39: PM2 log: ===============================================================================
PM2 | 2022-11-13T12:51:39: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
PM2 | 2022-11-13T12:51:39: PM2 log: Time : Sun Nov 13 2022 12:51:39 GMT-0300 (Brasilia Standard Time)
PM2 | 2022-11-13T12:51:39: PM2 log: PM2 version : 5.2.0
PM2 | 2022-11-13T12:51:39: PM2 log: Node.js version : 16.16.0
PM2 | 2022-11-13T12:51:39: PM2 log: Current arch : arm64
PM2 | 2022-11-13T12:51:39: PM2 log: PM2 home : /var/root/.pm2
PM2 | 2022-11-13T12:51:39: PM2 log: PM2 PID file : /var/root/.pm2/pm2.pid
PM2 | 2022-11-13T12:51:39: PM2 log: RPC socket file : /var/root/.pm2/rpc.sock
PM2 | 2022-11-13T12:51:39: PM2 log: BUS socket file : /var/root/.pm2/pub.sock
PM2 | 2022-11-13T12:51:39: PM2 log: Application log path : /var/root/.pm2/logs
PM2 | 2022-11-13T12:51:39: PM2 log: Worker Interval : 30000
PM2 | 2022-11-13T12:51:39: PM2 log: Process dump file : /var/root/.pm2/dump.pm2
PM2 | 2022-11-13T12:51:39: PM2 log: Concurrent actions : 2
PM2 | 2022-11-13T12:51:39: PM2 log: SIGTERM timeout : 1600
PM2 | 2022-11-13T12:51:39: PM2 log: ===============================================================================
PM2 | 2022-11-13T12:51:39: PM2 log: App [test:0] starting in -fork mode-
PM2 | 2022-11-13T12:51:39: PM2 log: App [test:0] online
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
Start with the reported test.js reproduction and compare node test.js with pm2 start test.js --attach, focusing on how PM2 handles errors from async functions. Done means the custom uncaughtException handler executes under PM2 as it does with Node directly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- cli, devops
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100