From 6b636c051a0d563f742b33142790d06d991230e4 Mon Sep 17 00:00:00 2001 From: Skyxim Date: Sat, 16 Jul 2022 19:52:51 +0800 Subject: [PATCH] chore: Adjust the falling logic --- dns/doh.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dns/doh.go b/dns/doh.go index ca5b655c..20cc5f6b 100644 --- a/dns/doh.go +++ b/dns/doh.go @@ -7,6 +7,7 @@ import ( "github.com/Dreamacro/clash/component/dialer" "github.com/Dreamacro/clash/component/resolver" tls2 "github.com/Dreamacro/clash/component/tls" + "github.com/Dreamacro/clash/log" "github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go/http3" D "github.com/miekg/dns" @@ -71,6 +72,7 @@ func (dc *dohClient) doRequest(req *http.Request) (msg *D.Msg, err error) { client := &http.Client{Transport: dc.transport} resp, err := client.Do(req) if err != nil { + log.Errorln("doh %v", err) return nil, err } @@ -138,6 +140,7 @@ func newDohTransport(r *Resolver, preferH3 bool, proxyAdapter string) *dohTransp if err != nil { return nil, err } + if proxyAdapter == "" { return quic.DialAddrEarlyContext(ctx, net.JoinHostPort(ip.String(), port), tlsCfg, cfg) } else { @@ -173,7 +176,7 @@ func (doh *dohTransport) RoundTrip(req *http.Request) (*http.Response, error) { var fallbackErr bool defer func() { if doh.preferH3 && (h3Err || fallbackErr) { - doh.canUseH3.Store(doh.preferH3 && fallbackErr) + doh.canUseH3.Store(doh.preferH3 && (!h3Err || fallbackErr)) } }() @@ -182,7 +185,7 @@ func (doh *dohTransport) RoundTrip(req *http.Request) (*http.Response, error) { } req.Body = ioutil.NopCloser(bytes.NewReader(bodyBytes)) - if doh.preferH3 && doh.canUseH3.Load() { + if doh.canUseH3.Load() { resp, err = doh.h3.RoundTrip(req) h3Err = err != nil if !h3Err {