Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] 调整GEO数据库更新逻辑 #1864

Open
2 of 3 tasks
PDxtXHd opened this issue Feb 25, 2025 · 0 comments
Open
2 of 3 tasks

[Feature] 调整GEO数据库更新逻辑 #1864

PDxtXHd opened this issue Feb 25, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@PDxtXHd
Copy link

PDxtXHd commented Feb 25, 2025

验证步骤

  • 我已经阅读了 文档,确认了该功能没有实现
  • 我已在 Issue Tracker 中寻找过我要提出的功能请求,并且没有找到
  • 我是中文用户,而非其他语言用户

描述

根据测试,目前内核对GEO数据库的更新逻辑似乎是在启动时检查上次更新时间,如果距离上次更新时间已经达到geo-update-interval,则立刻进行更新,而在后续运行中不会再检查更新。
这就造成两个问题,其一,如果第一次更新没有成功,没有重试机制;其二,如果在启动时尚未达到触发更新的时间,而运行一段时间后达到,也不会更新,而是需要等到下次启动时再检查更新,对长时间不重新启动内核的使用场景不友好。
我之所以提出这个改进要求,也是基于实际使用中遇到的问题。如下是开启info级别日志并启动内核,从开始更新GEO数据库的日志片段(仅剔除了重复出现的level=info msg="[UDP] mihomo --> 223.5.5.5:853 doesn't match any rule using DIRECT"等DNS请求)
我发现,可能是由于GEO数据库更新这个行为发起的时间太早,本来应该走漏网之鱼策略组然后通过代理进行更新,但这个策略组里却还没有节点,处于[COMPATIBLE]状态(这个策略组我放置了url-test组和一些其他分组,且默认选择的是url-test组,怀疑是因为健康检查没做完所以这个组里还没节点)。通过这个出口无法更新,于是更新失败,继续运行。为了测试,我把两个GEO数据库都用几天前的文件覆盖,且把geo-update-interval缩短到了1h,而几个小时后发现日志里并没有再次尝试更新GEO的条目。
该情况并非百分之百复现,所以有时也能成功更新。目前我的临时解决方案是给漏网之鱼的策略组指定为某个select组,这样就不会在更新GEO数据库的时候处于[COMPATIBLE]状态,从而能正常更新。但这并不能解决启动时检查更新失败后没有重试机制的问题,也不能解决长期不重新启动内核时不自动检查更新的问题。
我猜测,GEO数据库更新之所以这么早启动,是因为想避免更新行为匹配规则时遇上GEO相关规则,出现鸡蛋问题,所以在本地没有数据库的情况下需要尽快尝试拉取。但本地没有数据库的情况一般只出现在首次运行时,一旦成功拉取,后续就不会再有类似问题。因此,我建议如果代码修改难度不是很大,开发组可以酌情考虑调整相关更新逻辑,例如延迟一些发起更新请求,或者加上重试/定时检查等

time="2025-02-25T16:55:12.805997735+08:00" level=info msg="[GEO] last update time 2025-02-20 18:43:41 +0800 CST"
time="2025-02-25T16:55:12.806112266+08:00" level=info msg="[GEO] Database has not been updated for 1h0m0s, update now"
time="2025-02-25T16:55:12.806140235+08:00" level=info msg="[GEO] Start updating GEO database"
time="2025-02-25T16:55:12.806169506+08:00" level=info msg="[GEO] Updating GEO database"
time="2025-02-25T16:55:12.809521589+08:00" level=warning msg="[TCP] dial 🐋 漏网之鱼 (match Match/) mihomo --> raw.githubusercontent.com:443 error: dial tcp 0.0.0.0:443: connect: connection refused"
time="2025-02-25T16:55:12.821234818+08:00" level=warning msg="[TCP] dial 🐋 漏网之鱼 (match Match/) mihomo --> raw.githubusercontent.com:443 error: dial tcp 0.0.0.0:443: connect: connection refused"
time="2025-02-25T16:55:12.835137683+08:00" level=warning msg="[TCP] dial 🐋 漏网之鱼 (match Match/) mihomo --> raw.githubusercontent.com:443 error: dial tcp 0.0.0.0:443: connect: connection refused"
time="2025-02-25T16:55:12.854052995+08:00" level=warning msg="[TCP] dial 🐋 漏网之鱼 (match Match/) mihomo --> raw.githubusercontent.com:443 error: dial tcp 0.0.0.0:443: connect: connection refused"
time="2025-02-25T16:55:12.917000131+08:00" level=warning msg="[TCP] dial 🐋 漏网之鱼 (match Match/) mihomo --> raw.githubusercontent.com:443 error: dial tcp 0.0.0.0:443: connect: connection refused"
time="2025-02-25T16:55:12.980779818+08:00" level=info msg="[TCP] mihomo --> github.com:443 match Match using 🐋 漏网之鱼[COMPATIBLE]"
time="2025-02-25T16:55:13.006742162+08:00" level=warning msg="[TCP] dial 🐋 漏网之鱼 (match Match/) mihomo --> raw.githubusercontent.com:443 error: dial tcp 0.0.0.0:443: connect: connection refused"
time="2025-02-25T16:55:13.307205599+08:00" level=warning msg="[TCP] dial 🐋 漏网之鱼 (match Match/) mihomo --> raw.githubusercontent.com:443 error: dial tcp 0.0.0.0:443: connect: connection refused"
time="2025-02-25T16:55:13.526507526+08:00" level=warning msg="[TCP] dial 🐋 漏网之鱼 (match Match/) mihomo --> raw.githubusercontent.com:443 error: dial tcp 0.0.0.0:443: connect: connection refused"
time="2025-02-25T16:55:13.547130703+08:00" level=info msg="[TCP] mihomo --> github.com:443 match Match using 🐋 漏网之鱼[COMPATIBLE]"

@PDxtXHd PDxtXHd added the enhancement New feature or request label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant