diff --git a/app/dns/dns.go b/app/dns/dns.go index af5f285b..6efcb825 100644 --- a/app/dns/dns.go +++ b/app/dns/dns.go @@ -215,7 +215,7 @@ func (s *DNS) LookupIP(domain string, option dns.IPOption) ([]net.IP, error) { newError("failed to lookup ip for domain ", domain, " at server ", client.Name()).Base(err).WriteToLog() errs = append(errs, err) } - if err != context.Canceled && err != context.DeadlineExceeded && err != errExpectedIPNonMatch { + if err != context.Canceled && err != context.DeadlineExceeded && err != errExpectedIPNonMatch && err != dns.ErrEmptyResponse { return nil, err } } diff --git a/app/dns/dns_test.go b/app/dns/dns_test.go index b3a8def8..74c7a125 100644 --- a/app/dns/dns_test.go +++ b/app/dns/dns_test.go @@ -13,6 +13,7 @@ import ( _ "github.com/xtls/xray-core/app/proxyman/outbound" "github.com/xtls/xray-core/app/router" "github.com/xtls/xray-core/common" + "github.com/xtls/xray-core/common/errors" "github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/serial" "github.com/xtls/xray-core/core" @@ -260,7 +261,7 @@ func TestUDPServer(t *testing.T) { IPv6Enable: true, FakeEnable: false, }) - if err != feature_dns.ErrEmptyResponse { + if !errors.AllEqual(feature_dns.ErrEmptyResponse, errors.Cause(err)) { t.Fatal("error: ", err) } if len(ips) != 0 { diff --git a/common/errors/multi_error.go b/common/errors/multi_error.go index 8f19c97a..8066ac9e 100644 --- a/common/errors/multi_error.go +++ b/common/errors/multi_error.go @@ -28,3 +28,20 @@ func Combine(maybeError ...error) error { } return errs } + +func AllEqual(expected error, actual error) bool { + switch errs := actual.(type) { + case multiError: + if len(errs) == 0 { + return false + } + for _, err := range errs { + if err != expected { + return false + } + } + return true + default: + return errs == expected + } +} diff --git a/proxy/dns/dns.go b/proxy/dns/dns.go index be05e4f7..4aa5dac0 100644 --- a/proxy/dns/dns.go +++ b/proxy/dns/dns.go @@ -8,6 +8,7 @@ import ( "github.com/xtls/xray-core/common" "github.com/xtls/xray-core/common/buf" + "github.com/xtls/xray-core/common/errors" "github.com/xtls/xray-core/common/net" dns_proto "github.com/xtls/xray-core/common/protocol/dns" "github.com/xtls/xray-core/common/session" @@ -232,7 +233,7 @@ func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string, } rcode := dns.RCodeFromError(err) - if rcode == 0 && len(ips) == 0 && err != dns.ErrEmptyResponse { + if rcode == 0 && len(ips) == 0 && !errors.AllEqual(dns.ErrEmptyResponse, errors.Cause(err)) { newError("ip query").Base(err).WriteToLog() return }