Skip to content

fix: 区分核心和 watchdog 运行状态#5220

Closed
eyaeya wants to merge 1 commit into
vernesong:devfrom
eyaeya:net/core-instance-running-state
Closed

fix: 区分核心和 watchdog 运行状态#5220
eyaeya wants to merge 1 commit into
vernesong:devfrom
eyaeya:net/core-instance-running-state

Conversation

@eyaeya

@eyaeya eyaeya commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Dependency chain

无依赖,可独立合并。建议在继续处理启动 generation guard 前合入,先修正基础运行状态判断。

问题现象

OpenClash 的 watchdog 也是 openclash 服务下的一个 procd instance。当前 start_serviceprocd_running "openclash" 判断是否已运行,watchdog 只要还活着,就可能让手动 start 误判为核心已运行。watchdog 自身也用 instances.*.running 判断服务状态,可能把自己算作核心存活。

根因

core instance 名为 openclash,watchdog instance 名为 openclash-watchdog。现有判断只看服务任意 instance,而不是明确检查 core instance。

证据

  • init 脚本中 core 用 procd_open_instance "openclash" 启动。
  • watchdog 用 procd_open_instance "openclash-watchdog" 启动。
  • 旧的 procd_running "openclash"instances.*.running 会把 watchdog 存活误当成 core 存活。
  • 新增 tests/openclash_core_instance_state_test.sh 覆盖 start 和 watchdog 的 core instance 判断。

修复方案

  • start_service 改为 procd_running "openclash" "openclash",只在 core instance 运行时报告 Already Running。
  • watchdog 状态检查改为读取 @.openclash.instances.openclash.running,不再把 openclash-watchdog 算作 core。

为什么没有扩大范围

本 PR 不改变 stop 流程中等待整个服务停止的逻辑,也不改 respawn、PID、TUN/API 检查或防火墙清理。旧后台启动检查反杀新启动的问题需要 generation/PID guard,属于后续独立修复。

与已有开启态 PR 的关系

验证

  • bash -n luci-app-openclash/root/usr/share/openclash/*.sh:通过
  • bash -n luci-app-openclash/root/etc/init.d/openclash:通过
  • bash -n tests/*.sh:通过
  • for t in tests/*.sh; do bash "$t"; done:全部通过
  • git diff --check:通过
  • rg -n '^(<<<<<<<|=======|>>>>>>>)':无匹配

未做 live router 写入验证。

剩余风险

该修复只解决“watchdog 存活导致核心状态误判”。如果旧的后台启动检查仍在等待并最终失败,仍可能反向停止新启动;这需要单独 generation guard 修复。

@eyaeya

eyaeya commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

这个拆分 PR 已被新的合并版 PR 取代:#5230

原因:#5220#5221#5225 都属于 OpenClash 启停生命周期竞态修复,并且同时处理时会在 luci-app-openclash/root/etc/init.d/openclash 产生真实冲突。新的合并版 PR 保留了本 PR 的行为,同时把 core/watchdog 状态、启动 generation guard、生命周期锁统一整理成单个 reviewer 友好的提交。

已在合并版 PR 中验证:

  • focused tests
  • init.d/openclash 与 watchdog 脚本语法检查
  • git diff --check
  • conflict marker scan
  • 多轮对抗式复核,最终无修改点

@eyaeya eyaeya closed this Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant