diff --git a/go.mod b/go.mod index f4e57a36b1..1291146197 100644 --- a/go.mod +++ b/go.mod @@ -57,7 +57,7 @@ require ( howett.net/plist v1.0.1 ) -replace github.com/sagernet/sing-dns v0.2.0 => github.com/puernya/sing-dns v0.0.0-20240701164015-ea3006b2aef3 +replace github.com/sagernet/sing-dns v0.2.0 => github.com/puernya/sing-dns v0.0.0-20240701174700-43d7ed913da8 replace github.com/sagernet/sing-tun v0.3.2 => github.com/puernya/sing-tun v0.0.0-20240613145259-aafb943eaa33 diff --git a/go.sum b/go.sum index 860caea017..1983dc3896 100644 --- a/go.sum +++ b/go.sum @@ -94,8 +94,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/puernya/sing v0.0.0-20240627172524-ee861d432144 h1:talOEvqGoz1zanPj1YTRWYKK68jAlh9eoE6yio7aLJo= github.com/puernya/sing v0.0.0-20240627172524-ee861d432144/go.mod h1:ieZHA/+Y9YZfXs2I3WtuwgyCZ6GPsIR7HdKb1SdEnls= -github.com/puernya/sing-dns v0.0.0-20240701164015-ea3006b2aef3 h1:hlIFBhCy4SE+9DZ1X4aD1rfqnwp31EysDDXaikJzXvI= -github.com/puernya/sing-dns v0.0.0-20240701164015-ea3006b2aef3/go.mod h1:BJpJv6XLnrUbSyIntOT6DG9FW0f4fETmPAHvNjOprLg= +github.com/puernya/sing-dns v0.0.0-20240701174700-43d7ed913da8 h1:MOyI5aCVvZY38aFeqjJPUAEwJG4RwZgESutFCd/mFXI= +github.com/puernya/sing-dns v0.0.0-20240701174700-43d7ed913da8/go.mod h1:BJpJv6XLnrUbSyIntOT6DG9FW0f4fETmPAHvNjOprLg= github.com/puernya/sing-tun v0.0.0-20240613145259-aafb943eaa33 h1:Pg43kMURcQxpDEBwH7HUUE87RT6O6G6WkInwLJsTE4c= github.com/puernya/sing-tun v0.0.0-20240613145259-aafb943eaa33/go.mod h1:DxLIyhjWU/HwGYoX0vNGg2c5QgTQIakphU1MuERR5tQ= github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= diff --git a/route/router_dns.go b/route/router_dns.go index 86a831dff5..a65f674069 100644 --- a/route/router_dns.go +++ b/route/router_dns.go @@ -8,7 +8,6 @@ import ( "time" "github.com/sagernet/sing-box/adapter" - C "github.com/sagernet/sing-box/constant" "github.com/sagernet/sing-box/log" "github.com/sagernet/sing-dns" "github.com/sagernet/sing/common/cache" @@ -178,13 +177,11 @@ func (r *Router) exchangeFunc(ctx context.Context, message *mDNS.Msg, isCacheUpd for { var ( dnsCtx context.Context - cancel context.CancelFunc addressLimit bool ) dnsCtx, transport, strategy, rule, ruleIndex, isFakeIP = r.matchDNS(ctx, true, ruleIndex) isisAddrReq := isAddressQuery(message) - dnsCtx, cancel = context.WithTimeout(dnsCtx, C.DNSTimeout) if rule != nil && rule.WithAddressLimit() && isisAddrReq { addressLimit = true response, err = r.dnsClient.ExchangeWithResponseCheck(dnsCtx, transport, message, strategy, isCacheUpdate, func(response *mDNS.Msg) bool { @@ -195,17 +192,16 @@ func (r *Router) exchangeFunc(ctx context.Context, message *mDNS.Msg, isCacheUpd addressLimit = false response, err = r.dnsClient.Exchange(dnsCtx, transport, message, strategy, isCacheUpdate) } - cancel() var rejected bool if err != nil { if errors.Is(err, dns.ErrResponseRejectedCached) { rejected = true - r.dnsLogger.DebugContext(ctx, E.Cause(err, "response rejected for ", formatQuestion(message.Question[0].String())), " (cached)") + r.dnsLogger.DebugContext(ctx, E.Cause(err, "response rejected for ", formatQuestion(message.Question[0].String())), " (cached)") } else if errors.Is(err, dns.ErrResponseRejected) { rejected = true - r.dnsLogger.DebugContext(ctx, E.Cause(err, "response rejected for ", formatQuestion(message.Question[0].String()))) + r.dnsLogger.DebugContext(ctx, E.Cause(err, "response rejected for ", formatQuestion(message.Question[0].String()))) } else if len(message.Question) > 0 { - r.dnsLogger.ErrorContext(ctx, E.Cause(err, "exchange failed for ", formatQuestion(message.Question[0].String()))) + r.dnsLogger.ErrorContext(ctx, E.Cause(err, "exchange failed for ", formatQuestion(message.Question[0].String()))) } else { r.dnsLogger.ErrorContext(ctx, E.Cause(err, "exchange failed for ")) } @@ -247,9 +243,7 @@ func (r *Router) exchangeFunc(ctx context.Context, message *mDNS.Msg, isCacheUpd if transport == nil { continue } - dnsCtx, cancel = context.WithTimeout(dnsCtx, C.DNSTimeout) response, err = r.dnsClient.Exchange(dnsCtx, transport, message, strategy, isCacheUpdate) - cancel() if isFakeIP { break } @@ -353,13 +347,11 @@ func (r *Router) lookupFunc(ctx context.Context, domain string, strategy dns.Dom for { var ( dnsCtx context.Context - cancel context.CancelFunc addressLimit bool ) metadata.ResetRuleCache() metadata.DestinationAddresses = nil dnsCtx, transport, transportStrategy, rule, ruleIndex, _ = r.matchDNS(ctx, false, ruleIndex) - dnsCtx, cancel = context.WithTimeout(dnsCtx, C.DNSTimeout) if strategy == dns.DomainStrategyAsIS { strategy = transportStrategy } @@ -373,20 +365,19 @@ func (r *Router) lookupFunc(ctx context.Context, domain string, strategy dns.Dom addressLimit = false responseAddrs, err = r.dnsClient.Lookup(dnsCtx, transport, domain, strategy, isCacheUpdate) } - cancel() var rejected bool if err != nil { if errors.Is(err, dns.ErrResponseRejectedCached) { rejected = true - r.dnsLogger.DebugContext(ctx, "response rejected for ", domain, " (cached)") + r.dnsLogger.DebugContext(ctx, "response rejected for ", domain, " (cached)") } else if errors.Is(err, dns.ErrResponseRejected) { rejected = true - r.dnsLogger.DebugContext(ctx, "response rejected for ", domain) + r.dnsLogger.DebugContext(ctx, "response rejected for ", domain) } else { r.dnsLogger.ErrorContext(ctx, E.Cause(err, "lookup failed for ", domain)) } } else if len(responseAddrs) == 0 { - r.dnsLogger.ErrorContext(ctx, "lookup failed for ", domain, ": empty result") + r.dnsLogger.ErrorContext(ctx, "lookup failed for ", domain, ": empty result") err = dns.RCodeNameError } else { r.dnsLogger.InfoContext(ctx, "lookup succeed for ", domain, ": ", strings.Join(F.MapToString(responseAddrs), " ")) @@ -418,13 +409,11 @@ func (r *Router) lookupFunc(ctx context.Context, domain string, strategy dns.Dom if transport == nil { continue } - dnsCtx, cancel = context.WithTimeout(dnsCtx, C.DNSTimeout) responseAddrs, err = r.dnsClient.Lookup(dnsCtx, transport, domain, strategy, isCacheUpdate) - cancel() if err != nil { - r.dnsLogger.ErrorContext(ctx, E.Cause(err, "lookup failed for ", domain)) + r.dnsLogger.ErrorContext(ctx, E.Cause(err, "lookup failed for ", domain)) } else if len(responseAddrs) == 0 { - r.dnsLogger.ErrorContext(ctx, "lookup failed for ", domain, ": empty result") + r.dnsLogger.ErrorContext(ctx, "lookup failed for ", domain, ": empty result") err = dns.RCodeNameError } else { r.dnsLogger.InfoContext(ctx, "lookup succeed for ", domain, ": ", strings.Join(F.MapToString(responseAddrs), " "))