net/dns/resolver: add better error wrapping

To aid in debugging exactly what's going wrong, instead of the
not-particularly-useful "dns udp query: context deadline exceeded" error
that we currently get.

Updates #3786
Updates #10768
Updates #11620
(etc.)

Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
Change-Id: I76334bf0681a8a2c72c90700f636c4174931432c
pull/11979/head
Andrew Dunham 7 months ago
parent e0287a4b33
commit f97d0ac994

@ -859,7 +859,7 @@ func (f *forwarder) forwardWithDestChan(ctx context.Context, query packet, respo
} }
select { select {
case <-ctx.Done(): case <-ctx.Done():
return ctx.Err() return fmt.Errorf("waiting to send NXDOMAIN: %w", ctx.Err())
case responseChan <- res: case responseChan <- res:
return nil return nil
} }
@ -885,7 +885,7 @@ func (f *forwarder) forwardWithDestChan(ctx context.Context, query packet, respo
} }
select { select {
case <-ctx.Done(): case <-ctx.Done():
return ctx.Err() return fmt.Errorf("waiting to send SERVFAIL: %w", ctx.Err())
case responseChan <- res: case responseChan <- res:
return nil return nil
} }
@ -915,6 +915,7 @@ func (f *forwarder) forwardWithDestChan(ctx context.Context, query packet, respo
} }
resb, err := f.send(ctx, fq, *rr) resb, err := f.send(ctx, fq, *rr)
if err != nil { if err != nil {
err = fmt.Errorf("resolving using %q: %w", rr.name.Addr, err)
select { select {
case errc <- err: case errc <- err:
case <-ctx.Done(): case <-ctx.Done():
@ -936,7 +937,7 @@ func (f *forwarder) forwardWithDestChan(ctx context.Context, query packet, respo
select { select {
case <-ctx.Done(): case <-ctx.Done():
metricDNSFwdErrorContext.Add(1) metricDNSFwdErrorContext.Add(1)
return ctx.Err() return fmt.Errorf("waiting to send response: %w", ctx.Err())
case responseChan <- packet{v, query.family, query.addr}: case responseChan <- packet{v, query.family, query.addr}:
metricDNSFwdSuccess.Add(1) metricDNSFwdSuccess.Add(1)
return nil return nil
@ -969,7 +970,16 @@ func (f *forwarder) forwardWithDestChan(ctx context.Context, query packet, respo
metricDNSFwdErrorContextGotError.Add(1) metricDNSFwdErrorContextGotError.Add(1)
return firstErr return firstErr
} }
return ctx.Err()
// If we haven't got an error or a successful response,
// include all resolvers in the error message so we can
// at least see what what servers we're trying to
// query.
var resolverAddrs []string
for _, rr := range resolvers {
resolverAddrs = append(resolverAddrs, rr.name.Addr)
}
return fmt.Errorf("waiting for response or error from %v: %w", resolverAddrs, ctx.Err())
} }
} }
} }

Loading…
Cancel
Save