From d4e3d4344a020c347d1a85f22b5165a96c06187f Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Mon, 21 Aug 2017 11:01:36 +0200 Subject: [PATCH] dns: refactor label by unrolling loop --- agent/dns.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/agent/dns.go b/agent/dns.go index 2ec92b4908..f3856fe9e4 100644 --- a/agent/dns.go +++ b/agent/dns.go @@ -692,22 +692,27 @@ func (d *DNSServer) serviceLookup(network, datacenter, service, tag string, req, AllowStale: *d.config.AllowStale, }, } + var out structs.IndexedCheckServiceNodes -RPC: if err := d.agent.RPC("Health.ServiceNodes", &args, &out); err != nil { d.logger.Printf("[ERR] dns: rpc error: %v", err) resp.SetRcode(req, dns.RcodeServerFailure) return } - // Verify that request is not too stale, redo the request - if args.AllowStale { - if out.LastContact > d.config.MaxStale { - args.AllowStale = false - d.logger.Printf("[WARN] dns: Query results too stale, re-requesting") - goto RPC - } else if out.LastContact > staleCounterThreshold { - metrics.IncrCounter([]string{"consul", "dns", "stale_queries"}, 1) + if args.AllowStale && out.LastContact > staleCounterThreshold { + metrics.IncrCounter([]string{"consul", "dns", "stale_queries"}, 1) + } + + // redo the request the response was too stale + if args.AllowStale && out.LastContact > d.config.MaxStale { + args.AllowStale = false + d.logger.Printf("[WARN] dns: Query results too stale, re-requesting") + + if err := d.agent.RPC("Health.ServiceNodes", &args, &out); err != nil { + d.logger.Printf("[ERR] dns: rpc error: %v", err) + resp.SetRcode(req, dns.RcodeServerFailure) + return } }