From 108d26ebea14599fe4acb7dc5e1d2c87a7a01d51 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Fri, 11 Dec 2020 17:49:47 +0100 Subject: Move .LocalAddr() out of goroutine (#4281) I don't have theory why this panics, but concurrency has something to do with it, so get the address before we call the goroutine. See #4271 Signed-off-by: Miek Gieben --- plugin/cache/handler.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'plugin/cache/handler.go') diff --git a/plugin/cache/handler.go b/plugin/cache/handler.go index 406ece8e6..350ec0bb0 100644 --- a/plugin/cache/handler.go +++ b/plugin/cache/handler.go @@ -49,11 +49,12 @@ func (c *Cache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) servedStale.WithLabelValues(server).Inc() // Adjust the time to get a 0 TTL in the reply built from a stale item. now = now.Add(time.Duration(ttl) * time.Second) + addr := w.LocalAddr() // See https://github.com/coredns/coredns/issues/4271, unclear how, but pull this out of the goroutine, and get the address here. go func() { if !do { setDo(rc) } - crr := &ResponseWriter{Cache: c, state: state, server: server, prefetch: true, remoteAddr: w.LocalAddr(), do: do} + crr := &ResponseWriter{Cache: c, state: state, server: server, prefetch: true, remoteAddr: addr, do: do} plugin.NextOrFailure(c.Name(), c.Next, ctx, crr, rc) }() } -- cgit v1.2.3