From df57d49d8d456604b992169ef0228362e73ee83b Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Sat, 2 Sep 2023 20:56:42 +0800 Subject: [PATCH] Fix: should check all ips need to fallback (#2915) --- dns/resolver.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dns/resolver.go b/dns/resolver.go index 89e36214..3a530918 100644 --- a/dns/resolver.go +++ b/dns/resolver.go @@ -18,6 +18,7 @@ import ( "github.com/Dreamacro/clash/log" D "github.com/miekg/dns" + "github.com/samber/lo" "golang.org/x/sync/singleflight" ) @@ -200,7 +201,7 @@ func (r *Resolver) exchangeWithoutCache(ctx context.Context, m *D.Msg) (msg *D.M isIPReq := isIPRequest(q) if isIPReq { - cache=true + cache = true return r.ipExchange(ctx, m) } @@ -332,7 +333,10 @@ func (r *Resolver) ipExchange(ctx context.Context, m *D.Msg) (msg *D.Msg, err er res := <-msgCh if res.Error == nil { if ips := msgToIP(res.Msg); len(ips) != 0 { - if !r.shouldIPFallback(ips[0]) { + shouldNotFallback := lo.EveryBy(ips, func(ip netip.Addr) bool { + return !r.shouldIPFallback(ip) + }) + if shouldNotFallback { msg, err = res.Msg, res.Error // no need to wait for fallback result return }