fix(pm2): 给 pm2 jlist 输出捕获加 maxBuffer,修大 fleet 下 start-bot ENOBUFS - #641
Merged
Conversation
现象:机器上 bot 数量较多时(实测 46 个 pm2 进程),dashboard/CLI 新建
bot 无法自动上线——`botmux start-bot <appId>` 在第一步 `pm2 jlist` 就抛
`spawnSync ... ENOBUFS`,还没开始拉起进程就失败。
根因:`pm2 jlist` 会把每个进程的完整 env + 元数据序列化进 stdout,输出体积
随 bot 数近似线性增长;本机 jlist 已达 ~1.6 MB。而捕获它的两处 spawnSync
(cli.ts `pm2Capture`、core/plugins/pm2.ts `capturePluginPm2`)都没设
maxBuffer,用的是 Node 默认 1 MiB 上限 → 超限即 ENOBUFS。阈值约 30 个进程,
本机早已越过。既有 bot 不受影响(daemon 冷启动/restart 走批量 pm2 start
路径),只有单条 start-bot 读 jlist 时中招,所以表现为“老 bot 正常、新建
bot 起不来”。
修复:两处捕获 jlist 的 spawnSync 都加 `maxBuffer: 64 * 1024 * 1024`,远高于
任何真实 fleet 规模。与仓库其它大输出捕获(ps `-axww` 32 MiB、
session-discovery 16 MiB)一致。
验证:
- 复现:默认 maxBuffer 跑 `pm2 jlist`(1.6 MB)→ ENOBUFS;加 64 MiB → 正常
读全量。
- 修后 `node dist/cli.js start-bot <卡住的 appId> --json` → {"ok":true,
"state":"started","processName":"botmux-45"},该 bot 真正上线(pm2 online)。
- pnpm build 绿;bot-live-control / plugin-pm2-env / pm2-command 15/15 全过。
Co-Authored-By: Riff <noreply@riff.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
机器上 bot 数量较多时(实测 46 个 pm2 进程),dashboard/CLI 新建 bot 无法自动上线:
botmux start-bot <appId>在第一步pm2 jlist就抛spawnSync … ENOBUFS,还没开始拉起进程就失败。live 复现于生产 box(申晗手动 dashboard 扫码建 bot,写进 bots.json 但没起进程)。根因
pm2 jlist把每个进程的完整 env + 元数据序列化进 stdout,体积随 bot 数近似线性增长;本机 jlist 已达 ~1.6 MB。而捕获它的两处spawnSync都没设maxBuffer,用 Node 默认 1 MiB 上限 → 超限即ENOBUFS。阈值约 30 个进程,本机早已越过。src/cli.tspm2Capture(start-bot / status / inspect 都走它)src/core/plugins/pm2.tscapturePluginPm2(plugin service-manager 读 jlist,同样的潜在 bug)既有 bot 不受影响——daemon 冷启动 / restart 走批量 pm2 start路径;只有单条 start-bot 读 jlist 时中招,故表现为「老 bot 正常、新建 bot 起不来」。
改动
两处捕获 jlist 的 spawnSync 都加
maxBuffer: 64 * 1024 * 1024,远高于任何真实 fleet 规模。与仓库其它大输出捕获一致(ps -axww32 MiB、session-discovery 16 MiB、cli-runtime-update 2 MiB)。影响面
runPm2(stdio inherit,不缓冲)不受影响、无需改。验证
pm2 jlist(1.6 MB)→ ENOBUFS;加 64 MiB → 正常读全量。node dist/cli.js start-bot <卡住的 appId> --json→{"ok":true,"state":"started","processName":"botmux-45"},该 bot 真正上线(pm2 online, pid 存在)。pnpm build绿;bot-live-control/plugin-pm2-env/pm2-command15/15 全过。🤖 与 PR #629 无关,独立修复。