From 19ce6b7f5f17e58e85a8587fe97e4f3a0d2f6916 Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Fri, 18 Oct 2019 11:48:51 +0200 Subject: [PATCH] discovery: fix more error logs on context cancelation (#6133) Signed-off-by: Simon Pasquier --- discovery/consul/consul.go | 7 +++++++ discovery/dns/dns.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/discovery/consul/consul.go b/discovery/consul/consul.go index ccc09b072..f0db8d762 100644 --- a/discovery/consul/consul.go +++ b/discovery/consul/consul.go @@ -357,6 +357,13 @@ func (d *Discovery) watchServices(ctx context.Context, ch chan<- []*targetgroup. elapsed := time.Since(t0) rpcDuration.WithLabelValues("catalog", "services").Observe(elapsed.Seconds()) + // Check the context before in order to exit early. + select { + case <-ctx.Done(): + return + default: + } + if err != nil { level.Error(d.logger).Log("msg", "Error refreshing service list", "err", err) rpcFailuresCount.Inc() diff --git a/discovery/dns/dns.go b/discovery/dns/dns.go index 8710bf327..014d5239e 100644 --- a/discovery/dns/dns.go +++ b/discovery/dns/dns.go @@ -151,7 +151,7 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) { wg.Add(len(d.names)) for _, name := range d.names { go func(n string) { - if err := d.refreshOne(ctx, n, ch); err != nil { + if err := d.refreshOne(ctx, n, ch); err != nil && err != context.Canceled { level.Error(d.logger).Log("msg", "Error refreshing DNS targets", "err", err) } wg.Done()