fix: 仅当 fork 子进程完整引导 Chromium 时注入 --no-sandbox (#2045)

纯 Node 环境(如 NapCat.Shell.Windows.Node)下 child_process.fork 的
execArgv 会直接传给 node.exe;--no-sandbox 是 Chromium 开关,Node 不识别,
Worker 以退出码 9 (bad option) 启动失败并触发三次重启后主进程退出。

#1984 在非 Electron 路径无条件注入该参数,同样影响以 ELECTRON_RUN_AS_NODE
驱动 Electron 二进制的容器环境:node 模式与上游 Node 一致拒绝未知开关
(该变量存在即触发 node 模式,与取值无关)。

将注入条件从 !isElectron 收窄为「fork 路径 && 宿主为 Electron 二进制 &&
未设 ELECTRON_RUN_AS_NODE」:QQNT 主进程 fork 出的子进程不带
ELECTRON_RUN_AS_NODE、完整引导 Chromium,由 Chromium 解析该参数以规避
proot 沙箱 SIGSEGV,#1984 行为保持不变;纯 Node 路径不再传入,Worker
正常启动,并恢复 fork 对 process.execArgv 的默认继承。

Fixes #2040
This commit is contained in:
Shxiao authored and GitHub committed 2026-09-09 13:38:46 +08:00
1 parent 96de2314b0
commit 109d0c1dff
1 file changed
+8 -1
+8 -1
View File
@@ -247,7 +247,14 @@ async function startWorker (passQuickLogin: boolean = true, secretKey?: string,
...(preferredPort ? { NAPCAT_WEBUI_PREFERRED_PORT: String(preferredPort) } : {}),
},
stdio: isElectron ? 'pipe' : ['inherit', 'pipe', 'pipe', 'ipc'],
...(!isElectron ? { execArgv: ['--no-sandbox'] } : {}),
// --no-sandbox 是 Chromium 开关,仅当子进程完整引导 Electron(未设 ELECTRON_RUN_AS_NODE)时
// 才会被解析;纯 Node / Electron node 模式子进程会因 bad option 以退出码 9 拒绝启动
// (ELECTRON_RUN_AS_NODE 变量存在即触发 node 模式,与取值无关)
...(!isElectron &&
process.versions['electron'] &&
process.env['ELECTRON_RUN_AS_NODE'] === undefined
? { execArgv: ['--no-sandbox'] }
: {}),
});
currentWorker = child;