-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat(dns): add parallel query #5239
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
Conversation
67cef37 to
8b8abe9
Compare
|
Is there any with combination of 5237 and 5239? |
https://github.com/Meo597/Xray-core/actions/runs/18633074311 |
This comment was marked as resolved.
This comment was marked as resolved.
|
第一版糊的太粗糙了 因为一旦发现需要过滤 IP 就退出竞速模式(虽然并发请求,但是等所有结果返回再匹配) 而且除 IP 过滤外, 现在改了第二版: 为了不增加用户心智负担,特意把并发查询做成傻瓜模式 现在的设计能完全 cover 需求,并解决了这些坑:
{
"dns": {
"servers": [
// 走直连试探 geosite:cn
// 要求必须返回中国IP
{
"tag": "dns-direct",
"address": "223.5.5.5",
"skipFallback": true,
"domains": ["geosite:cn"],
"expectIPs": ["geoip:cn"]
},
{
"tag": "dns-direct",
"address": "114.114.114.114",
"skipFallback": true,
"domains": ["geosite:cn"],
"expectIPs": ["geoip:cn"]
},
// 走代理试探 geosite:geolocation-!cn
// 要求必须返回国外IP
{
"address": "8.8.8.8",
"skipFallback": true,
"domains": ["geosite:geolocation-!cn"],
"expectIPs": ["geoip:!cn"]
},
{
"address": "1.1.1.1",
"skipFallback": true,
"domains": ["geosite:geolocation-!cn"],
"expectIPs": ["geoip:!cn"]
},
{
// 未知域名、或者是上面规则回落下来的
// 走代理,但用ECS试探是不是在中国
// 不是就继续回落,获取代理CDN友好的IP
"address": "8.8.8.8",
"clientIp": "222.85.85.85", // 你当地ISP的地址,这样直连CDN友好
"skipFallback": false,
"expectIPs": ["geoip:cn"]
},
{
"address": "8.8.4.4",
"clientIp": "222.85.85.85",
"skipFallback": false,
"expectIPs": ["geoip:cn"]
},
"1.1.1.1"
],
"tag": "dns-proxy",
"enableParallelQuery": true
}
}
|
|
目前三个 PR 在我的用例下测了几天,没发现什么问题。 只是设计上仍有些小瑕疵:
仅备忘,暂时不想动了 |
|
@t-e-s-tweb |
Yes. This is the one that I am using. Its working fine. Only the logs show context cancelled or empty responses but the sites are browsable and connecting. But there isn't anyway to check if cache is being hit or optimistic is being used. Parallel queries logs do show them working. |
|
因为我把 debug 日志那几行给注释掉了,它们设计的不好,太“重”了 我晚点看一下 ctx 取消是咋回事 |
Thanks. Here is the complete logcat for the domain. |
之前就猜测过这块可能有问题,但我只用 udp 所以没发现 |
|
然后被我注释掉的那两行 cache debug log 因为我搜了下各种热点函数都在 errors.LogDebug Logger 应该先判定 level 再拼字符串 |
|
@t-e-s-tweb 感谢测试与反馈!
现在,非 disableCache 的服务器,处于并发查询模式下,会忽略 caller 的 ctx.cancel() 以充分预热缓存。
把 debug 日志加回去了。 测试时还发现一个 xray 原有的 bug: 其实这样还是有问题,如果什么 app 无视 rcode 3 疯狂重试 |
|
@Meo597 rebase |
639a2f1 to
77c064c
Compare
|
ok |


{ // 示例配置 "dns": { "enableParallelQuery": true } }DNS 回退(failover)默认是串行的,即默认仅在选中的 DNS 服务器查询失败或
expectedIPs和unexpectedIPs不匹配后才向下一台服务器发起查询。串行意味着服务器正常时,每次 failover 都需要 1 rtt;而服务器故障时,每次 failover 都需要等
timeoutMs默认 4 秒。启用并行查询后,会预先向所有被选中的 DNS 服务器异步发起查询,并执行“动态分组,组内竞速,组间回退”的策略。
并行意味着无论你的 DNS 规则有多复杂,可能会 failover 无数次,都仅需 1 rtt,规则链中也不再有单点故障,导致硬等
timeoutMs4 秒。动态分组,被选中的服务器列表中相邻的服务器如果
clientIPskipfailoverqueryStrategytagdomainsexpectedIPsunexpectedIPs完全一样,被视为同一个组。组内竞速,同组内只要任意一 DNS 服务器查询成功且
expectedIPs和unexpectedIPs匹配到了 IP,则本组视为成功,同时忽略本组其它服务器的结果 (它们的查询仍会继续,以预热缓存,如果 disableCache: false)。组间回退,若第一个组还在查询,则等待。若第一个组成功,则返回 IP。若第一个组所有服务器都查询失败或 IP 不匹配,则回退到下一个组。最终若所有组都失败,则返回空解析。
感谢 @t-e-s-tweb 的测试与反馈!