Repository navigation
Closed
Description
简述 / Description
Xray-core 内部 DNS 缓存无视上游服务器返回的真实 TTL(例如 3600s),其生存周期似乎被内部硬编码或截断为了最大 300 秒(5 分钟)。导致客户端在超过 5 分钟后再次请求相同域名时,Xray 必然发生内部缓存未命中(Cache Miss),从而被迫重新向分布式/本地上游发起 DoH 请求。
重现步骤 / Steps to Reproduce
- 配置上游 DoH 服务器(例如 AdGuardHome),设置最小 TTL 覆盖为
3600秒。 - 配置 Xray 的
dns模块,设置"disableCache": false,路由使用"domainStrategy": "IPOnDemand"。 - 客户端发起对某一域名(例如
www.example.com)的请求。 - 4 分钟时(未满 300 秒):再次请求该域名,Xray 日志正确显示
cache HIT,未触发上游查询。 - 5 分钟 30 秒时(超过 300 秒):再次请求该域名,Xray 缓存失效,日志显示重新开始
querying上游。
预期行为 / Expected Behavior
Xray 的内部 DNS 缓存应当尊重并严格执行上游返回的有效 TTL 值(如 3600 秒),在 3600 秒内不应频繁在内部过期并重新向外(或向本地环回)发送 DoH 请求。或者,如果这是一个出于路由安全设计的硬上限截断(Clamp),应当在 config.json 中提供参数可供用户自行调节。
实际行为 / Actual Behavior
无论上游返回的 TTL 有多大(经测试 A 和 AAAA 纪录均返回 3600),Xray 内部只要超过 300 秒就会单方面蒸发该域名的缓存。
通过 Debug 日志可以清晰地看到:在 5 分钟之后重新触发的查询中,上游回包的 RTT 仅为 1.08ms。这绝对性地证明了上游 DNS(如 AdGuardHome)的缓存其实并没有过期(仍在 3600s 内),完全是 Xray 内部提前把该纪录删除了,才引发了这次不必要的重新查询。
日志证据 / Logs
// 05:32:08 初始触发查询,写入缓存
2026/06/22 05:32:08 [Info] app/dns: DOHL//adguardhome.dns.server querying: [www.example.com](https://www.example.com).
2026/06/22 05:32:08 [Info] app/dns: DOHL//adguardhome.dns.server got answer: [www.example.com](https://www.example.com). TypeA -> [...], rtt: 1.077709ms
// 05:36:37(过去 4 分 29 秒,未满 5 分钟) -> 正常命中 Xray 缓存
2026/06/22 05:36:37 [Debug] app/dns: DOHL//adguardhome.dns.server cache HIT [www.example.com](https://www.example.com).
// 05:38:04(过去 5 分 56 秒,超过 5 分钟) -> Xray 内部过期,重新查询上游
// 注意:此时上游响应仅用时 1.08ms,证明上游缓存依旧存在,完全是 Xray 内部单方面抛弃了缓存
2026/06/22 05:38:04 [Info] app/dns: DOHL//adguardhome.dns.server querying: [www.example.com](https://www.example.com).
2026/06/22 05:38:04 [Info] app/dns: DOHL//adguardhome.dns.server got answer: [www.example.com](https://www.example.com). TypeA -> [...], rtt: 1.089398ms
环境信息
Xray-Core: 26.3.27
系统: Ubuntu 22.04.5 LTS
Upstream DNS: AdGuardHome via DoH (https+local://)
Metadata
Metadata
Assignees
Labels
No labels
Activity
Fangliding commentedon Jun 22, 2026
似乎是实现的BUG 会修复
Fangliding commentedon Jun 22, 2026
尝试一下 https://github.com/XTLS/Xray-core/actions/runs/27976400980
yang05051 commentedon Jun 23, 2026
十分感谢,能够确认这个问题被修复了。
同一个配置下,您的修复版本不存在该问题,而最新 Release 的版本能够复现。至此,可以确认您的修复起作用了。十分感谢您的修复。
附上测试时输出的日志(来自您的修复版本):
附上测试用的config:
{ "log": { "access": "/usr/local/etc/xray/log/access.log", "error": "/usr/local/etc/xray/log/error.log", "loglevel": "debug" }, "dns": { "servers": [ { "address": "127.0.0.1", "port": 30053 } ], "disableFallback": true, "disableCache": false }, "routing": { "domainStrategy": "IPOnDemand", "rules": [ { "type": "field", "outboundTag": "direct_", "network": "udp,tcp" } ] }, "inbounds": [ { "protocol": "socks", "listen": "127.0.0.1", "port": 10080, "settings": { "auth": "noauth" } } ], "outbounds": [ { "protocol": "freedom", "streamSettings": { "sockopt": { "domainStrategy": "UseIP", "happyEyeballs": { "tryDelayMs": 250, "prioritizeIPv6": false } } }, "tag": "direct_" } ] }DNS: Fix unexpected TTL clamp (#6363)
DNS: Fix unexpected TTL clamp (XTLS#6363)
Squashed commit of the following:
DNS: Fix unexpected TTL clamp (#6363)