From 21a965851928da12c06f2d39f3fa32e1e46f766a Mon Sep 17 00:00:00 2001 From: patterniha <71074308+patterniha@users.noreply.github.com> Date: Wed, 15 Oct 2025 00:29:04 +0330 Subject: [PATCH] Router: Use built-in-dns only once for all rules (in "IPOnDemand"/"IPIfNonMatch" mode) (#5210) --- features/routing/dns/context.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/features/routing/dns/context.go b/features/routing/dns/context.go index a65895f6..2cf9d261 100644 --- a/features/routing/dns/context.go +++ b/features/routing/dns/context.go @@ -12,14 +12,19 @@ import ( // ResolvableContext is an implementation of routing.Context, with domain resolving capability. type ResolvableContext struct { routing.Context - dnsClient dns.Client - resolvedIPs []net.IP + dnsClient dns.Client + cacheIPs []net.IP + hasError bool } // GetTargetIPs overrides original routing.Context's implementation. func (ctx *ResolvableContext) GetTargetIPs() []net.IP { - if len(ctx.resolvedIPs) > 0 { - return ctx.resolvedIPs + if len(ctx.cacheIPs) > 0 { + return ctx.cacheIPs + } + + if ctx.hasError { + return nil } if domain := ctx.GetTargetDomain(); len(domain) != 0 { @@ -29,16 +34,18 @@ func (ctx *ResolvableContext) GetTargetIPs() []net.IP { FakeEnable: false, }) if err == nil { - ctx.resolvedIPs = ips + ctx.cacheIPs = ips return ips } errors.LogInfoInner(context.Background(), err, "resolve ip for ", domain) } if ips := ctx.Context.GetTargetIPs(); len(ips) != 0 { + ctx.cacheIPs = ips return ips } + ctx.hasError = true return nil }