node进程cpu 超过100%进程重启,rejecting a promise which was not handled with .catch() 错误 怎么解决?
发布于 6 年前 作者 jackieli123723 4904 次浏览 来自 问答

xx app > (node:111493) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by x x xx rejecting a promise which was not handled with .catch(). (rejection id: 21) x x xx PM2 > App [app] with id [0] and pid [111493], exited with code [0] via signal [SIGKILL] x x xx PM2 > Starting execution sequence in -fork mode- for app name:app id:0

5 回复

promise 抛异常了咯,catch 处理一下

添加全局事件

process.on('unhandledRejection', (reason, p) => {
  console.log('未处理的 rejection:', p, '原因:', reason);
  // 记录日志
});

找到位置,把未处理的promise异常处理掉

@carlisliu

这个错误处理没问题了


process.on('unhandledRejection', (reason, p) => {
    console.log("Unhandled Rejection at: Promise ", p, " reason: ", reason);
    // application specific logging, throwing an error, or other logic here
});

process.on("uncaughtException", function(e) {
  console.log(e);
});

但是出现新的问题 程序还没运行完 就 killed 是什么原因呢?

@carlisliu 光这样处理可不够哦

先按日志fix bug,再上 Node.js 性能平台 做好监控,否则稳定性分分钟。。

回到顶部