Xray-core icon indicating copy to clipboard operation
Xray-core copied to clipboard

无效DNS结果被缓存, 只能重启xray进程

Open gubiao opened this issue 2 years ago • 5 comments

DNS服务器未返回有效的A记录或AAAA记录, 不存在TTL, 但是DNS解析结果仍然被xray内置DNS缓存, 发生这种情况后只能重启xray, 希望内置DNS仅缓存存在有效IP的, 有明确TTL的A记录或AAAA记录, 日志如下:

➜ ~ dig sdfsdf.sdf @127.0.0.1

; <<>> DiG 9.10.6 <<>> sdfsdf.sdf @127.0.0.1 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 16470 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION: ;sdfsdf.sdf. IN A

;; Query time: 6 msec ;; SERVER: 127.0.0.1#53(127.0.0.1) ;; WHEN: Wed Sep 28 20:10:38 CST 2022 ;; MSG SIZE rcvd: 28

日志: 2022/09/28 19:50:21 [Info] app/dns: UDP:119.29.29.29:53 got answer: sdfsdf.sdf. TypeA -> [] 10.821095ms 2022/09/28 19:50:21 [Debug] app/dns: UDP:119.29.29.29:53 updating IP records for domain:sdfsdf.sdf.

从日志中可以看出, DNS解析结果中TypeA对应的是一个空的数组, 此时是不存在带有TTL的有效A记录的, 此时不应该执行后续的“updating IP records for domain..."

https://github.com/XTLS/Xray-core/blob/main/app/dns/nameserver_udp.go 文件中的HandleResponse方法结尾处代码应考虑此类情况(空的数组?): if len(req.domain) > 0 && (rec.A != nil || rec.AAAA != nil) { s.updateIP(req.domain, &rec) }

gubiao avatar Sep 28 '22 12:09 gubiao

感谢你的详细分析 待修复

yuhan6665 avatar Sep 28 '22 12:09 yuhan6665

怪不得更新后就断断续续,"disableCache": true, 选项有作用么? 另外发现设置了 clientIP 后会上不了“远程”网。不知道是不是bug?

"dns": {
		"disableCache": true,
		"disableFallback": false,
		"disableFallbackIfMatch": false,
		"skipFallback": false,
		"queryStrategy": "UseIP",
		"tag": "dns_servers",
		"servers": [
			{
				"address": "223.5.5.5",
				"port": 53,
				"domains": [
					"geosite:geolocation-cn"
				],
				"expectIPs": [
					"geoip:cn"
				]
			},
			"208.67.222.222",
			"1.1.1.1"
		]
	},

BI7PRK avatar Sep 29 '22 07:09 BI7PRK

你们都是直接用xray代理dns的吗。我独立使用unbound dns缓存服务器会被影响吗

Smallthing avatar Oct 01 '22 09:10 Smallthing

不只是nameserver_udp.go里有这个问题。所有的nameserver_tcp/quic/doh.go里都有这个问题。

yuhan6665 @.***> 于2022年9月28日周三 20:47写道:

感谢你的详细分析 待修复

— Reply to this email directly, view it on GitHub https://github.com/XTLS/Xray-core/issues/1231#issuecomment-1260854107, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPLTYOD7DZQELWAWGEW67DWAQ44TANCNFSM6AAAAAAQXXBWO4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

changyp6 avatar Oct 11 '22 08:10 changyp6

Pending issue as far as I know

yuhan6665 avatar Apr 20 '24 18:04 yuhan6665