fix: 忽略过期启动检查失败 - #5221
Closed
eyaeya wants to merge 1 commit into
Closed
fix: 忽略过期启动检查失败#5221eyaeya wants to merge 1 commit into
eyaeya wants to merge 1 commit into
Conversation
This was referenced Jul 8, 2026
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
建议在 #5220 之后合并。#5220 先修正 core/watchdog instance 状态判断,本 PR 再处理旧启动检查反向影响新启动的问题。
问题现象
start_service会把check_core_status "start"放到后台等待 core、TUN 或控制接口就绪。如果用户或定时任务在旧检查还没结束时再次 restart,旧检查仍会使用全局pidof clash和当前网络状态判断。旧检查超时后会调用start_fail,从而把openclash.config.enable置 0 并 stop 当前服务,可能反向停止已经成功的新一轮启动。根因
后台状态检查没有与启动 generation 绑定。旧检查无法判断自己对应的启动轮次是否已经被新的 start/restart 取代。
证据
start_service原先在 Step 6 后台运行check_core_status "start" &。check_core_status超时路径会调用start_fail。start_fail会设置enable=0并执行stop。tests/openclash_start_generation_test.sh覆盖 start generation 文件、后台传参、stale failure 跳过和 stop 清理。修复方案
/tmp/openclash_start_id,每次 start 生成当前轮次 token。check_core_status接收该 token。start_fail在带 token 的后台检查中先确认 token 仍是当前轮次;如果已被新 start/restart 替换,则只记录并退出,不再停用/停止当前服务。stop_service清理 generation 文件,让停止期间遗留的后台检查自动变成 stale。为什么没有扩大范围
本 PR 不改变 core 启动命令、respawn、TUN/API 等待条件、防火墙规则或 DNS 设置。没有把所有启动流程串行化,也没有改前台配置失败的处理;只防止旧后台检查影响新一轮服务。
与已有开启态 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 写入验证。
剩余风险
该 guard 只保护带 generation token 的后台 core 状态检查。手动执行的 firewall/manual/restore 检查仍沿用原先行为,因为它们不是 start/restart 交叠导致的旧轮次问题。