Repository navigation
fix(core): legacy pm2 reaper 改为按 PATH 查找 pm2,不再执行探测泄漏 God - #1882
Merged
Merged
Conversation
`pm2 --version` 并非只读,会 daemonize 一个 God。旧探测把它跑在临时 PM2_HOME 里再 `pm2 kill` + 删目录,但 kill 可能超时,目录删掉后这个 God 就无人可寻址;而 resolvePm2Bin 在每次 `botmux start/restart` 都无条件执行, PATH 上有 pm2 的机器会随启动次数累积孤儿 God(实测 `botmux-pm2-probe-*`)。 - resolvePm2Bin:遍历 PATH 用 accessSync(X_OK) 查找,返回绝对路径,不执行 pm2 - reapLegacyPm2:只在确实发现旧 God 时才解析 pm2 CLI,常规启动完全不碰 pm2 - smoke-musl-reaper-probes 的 pm2 可达性检查同样改为文件查找 - 测试:无旧 God 时 PATH 上的 pm2 一次都不被执行;有旧 God 时仍走 PATH 上的 pm2(调用序列为 jlist / delete / kill,无 --version) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 13, 2026 14:42
仅 X_OK 会接受可遍历的同名目录,导致后续 pm2 调用 EACCES、旧 fleet 未被清理。 改用 src/utils/executable.ts 的 locateExecutable(要求普通文件)。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
Review 结论记录:
|
|
🚀 Released in v3.43.0 |
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.
问题
legacy-pm2-reaper的resolvePm2Bin用pm2 --version探测 PATH 上有没有 pm2,这个探测有两个问题:pm2 --version并非只读,它会 daemonize 一个 God。旧代码把它跑在临时PM2_HOME下,然后pm2 kill并删除目录。但pm2 kill可能超时,目录一旦删掉,这个 God 就再也无法通过 PM2_HOME 找到并关掉。resolvePm2Bin在reapLegacyPm2开头无条件执行,也就是每次botmux start/restart都会跑一遍,不管机器上有没有旧 God。结果是:PATH 上装了 pm2 的机器,会随着启动次数不断累积孤儿 God。在开发机上实测发现 3 个空跑的
botmux-pm2-probe-<pid>God,最早的已经跑了好几天。修复
resolvePm2Bin:遍历 PATH,用accessSync(X_OK)查找并返回绝对路径,不执行 pm2reapLegacyPm2:只在liveGodAt确实发现旧 God 后才解析 pm2 CLI(惰性求值,结果缓存)。新装或已完成迁移的机器在常规启动时完全不碰 pm2scripts/smoke-musl-reaper-probes.mjs里的 pm2 可达性检查也改为文件查找,仓库中不再有pm2 --version调用影响面
只改了
legacy-pm2-reaper的 pm2 CLI 解析,影响botmux start/restart/stop的迁移清理路径。没有 PATH pm2 的路径(编译态二进制、CI)行为不变。有旧 God 时依然走 pm2 CLI,调用序列不变(jlist/delete/kill),只是少了--version。代价是:如果 PATH 上的 pm2 可执行但实际跑不起来,之前探测阶段会把它判为不可用,现在要到后续jlist失败时才发现,并标记为unresolved。这和 CLI 在运行中失败时的处理方式一致。验证
npx tsc --noEmit、bun run build:通过npx vitest run test/legacy-pm2-reaper.test.ts:26 个全部通过--version」node scripts/smoke-musl-reaper-probes.mjs dist/core/legacy-pm2-reaper.js:all checks passedpgrep -f "God Daemon"没有任何残留bun test下treats a REAL orphaned socket … as no God1 个用例失败(卡在 bun 默认的 5s 超时)。master 上同样失败,与本 PR 无关🤖 Generated with Claude Code