From 7e5f1ccf3a03c94b420a6e3eac1c4edcf379ff65 Mon Sep 17 00:00:00 2001 From: yibo Date: Mon, 25 May 2026 12:55:58 +0800 Subject: [PATCH] fix: 加 unhandledRejection/uncaughtException 兜底防 node 崩溃 --- server/services/wechat/auto-reply.js | 10 ++++++++++ 1 file changed, 10 insertions(+), 0 deletions(-) diff --git a/server/services/wechat/auto-reply.js b/server/services/wechat/auto-reply.js index 99d956a..1a7e32a 100644 --- a/server/services/wechat/auto-reply.js +++ b/server/services/wechat/auto-reply.js @@ -1100,6 +1100,16 @@ class AutoReplyBot { // ═══════════════════════════════════════════════════════════════ if (require.main === module) { + // 全局兜底:Node 默认遇 unhandledRejection / uncaughtException 会退出进程, + // 流式 + sendChain Promise 链路某处漏接 reject 会导致 node 崩 → keepalive 重启 + // → 打断正在跑的 hermes run。这里捕获并记日志,保持进程存活。 + process.on('unhandledRejection', (reason) => { + log('[UNHANDLED REJECTION]', (reason && reason.stack) || String(reason)); + }); + process.on('uncaughtException', (err) => { + log('[UNCAUGHT EXCEPTION]', (err && err.stack) || String(err)); + }); + if (process.env.MY_WXID) CONFIG.myWxid = process.env.MY_WXID; if (process.env.MY_NICKNAME) CONFIG.myNickname = process.env.MY_NICKNAME; -- libgit2 0.21.4