Skip to content

Commit bfd5da2

Browse files
xinyiflyyuhan6665
authored andcommitted
fix: dns empty response
1 parent ae518cc commit bfd5da2

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

app/dns/dns.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func (s *DNS) LookupIP(domain string, option dns.IPOption) ([]net.IP, error) {
215215
newError("failed to lookup ip for domain ", domain, " at server ", client.Name()).Base(err).WriteToLog()
216216
errs = append(errs, err)
217217
}
218-
if err != context.Canceled && err != context.DeadlineExceeded && err != errExpectedIPNonMatch {
218+
if err != context.Canceled && err != context.DeadlineExceeded && err != errExpectedIPNonMatch && err != dns.ErrEmptyResponse {
219219
return nil, err
220220
}
221221
}

app/dns/dns_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
_ "github.com/xtls/xray-core/app/proxyman/outbound"
1414
"github.com/xtls/xray-core/app/router"
1515
"github.com/xtls/xray-core/common"
16+
"github.com/xtls/xray-core/common/errors"
1617
"github.com/xtls/xray-core/common/net"
1718
"github.com/xtls/xray-core/common/serial"
1819
"github.com/xtls/xray-core/core"
@@ -260,7 +261,7 @@ func TestUDPServer(t *testing.T) {
260261
IPv6Enable: true,
261262
FakeEnable: false,
262263
})
263-
if err != feature_dns.ErrEmptyResponse {
264+
if !errors.AllEqual(feature_dns.ErrEmptyResponse, errors.Cause(err)) {
264265
t.Fatal("error: ", err)
265266
}
266267
if len(ips) != 0 {

common/errors/multi_error.go

+17
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,20 @@ func Combine(maybeError ...error) error {
2828
}
2929
return errs
3030
}
31+
32+
func AllEqual(expected error, actual error) bool {
33+
switch errs := actual.(type) {
34+
case multiError:
35+
if len(errs) == 0 {
36+
return false
37+
}
38+
for _, err := range errs {
39+
if err != expected {
40+
return false
41+
}
42+
}
43+
return true
44+
default:
45+
return errs == expected
46+
}
47+
}

proxy/dns/dns.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/xtls/xray-core/common"
1010
"github.com/xtls/xray-core/common/buf"
11+
"github.com/xtls/xray-core/common/errors"
1112
"github.com/xtls/xray-core/common/net"
1213
dns_proto "github.com/xtls/xray-core/common/protocol/dns"
1314
"github.com/xtls/xray-core/common/session"
@@ -232,7 +233,7 @@ func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string,
232233
}
233234

234235
rcode := dns.RCodeFromError(err)
235-
if rcode == 0 && len(ips) == 0 && err != dns.ErrEmptyResponse {
236+
if rcode == 0 && len(ips) == 0 && !errors.AllEqual(dns.ErrEmptyResponse, errors.Cause(err)) {
236237
newError("ip query").Base(err).WriteToLog()
237238
return
238239
}

0 commit comments

Comments
 (0)