fix: 区分核心和 watchdog 运行状态#5220
Closed
eyaeya wants to merge 1 commit into
Closed
Conversation
This was referenced Jul 8, 2026
Closed
Closed
Contributor
Author
|
这个拆分 PR 已被新的合并版 PR 取代:#5230 原因:#5220、#5221、#5225 都属于 OpenClash 启停生命周期竞态修复,并且同时处理时会在 已在合并版 PR 中验证:
|
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.
Dependency chain
无依赖,可独立合并。建议在继续处理启动 generation guard 前合入,先修正基础运行状态判断。
问题现象
OpenClash 的 watchdog 也是
openclash服务下的一个 procd instance。当前start_service用procd_running "openclash"判断是否已运行,watchdog 只要还活着,就可能让手动 start 误判为核心已运行。watchdog 自身也用instances.*.running判断服务状态,可能把自己算作核心存活。根因
core instance 名为
openclash,watchdog instance 名为openclash-watchdog。现有判断只看服务任意 instance,而不是明确检查 core instance。证据
procd_open_instance "openclash"启动。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。@.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 修复。