healthcheck: answer 503 when no root server gave a usable reply in the last round of DNS checks (closes #302)
check / check (push) Waiting to run

The health check answered ok while every DNS lookup failed, as on a
network that intercepts DNS queries. A lookup whose root servers give no
usable reply now fails with ErrNoRootServerAnswered. At the end of each
round of DNS checks that shutdown did not cut short, the watcher records
whether every lookup failed with it or with ErrIntercepted; the health
check then gives status error, and /.well-known/healthcheck and /health
answer 503. Until the first round finishes it stays ok.

The health check now depends on the watcher, so fx starts the watcher
before the HTTP server and stops the server first. NewWithRootServers
lets tests start a resolver's walks at real servers that are not root
servers.

Model: opus-5-5
This commit was merged in pull request #304.
This commit is contained in:
2026-10-18 17:24:49 +02:00
parent b23cf43abf
commit 774f7caff6
14 changed files with 534 additions and 45 deletions
+10 -5
View File
@@ -293,7 +293,8 @@ func shuffled(
// place. Otherwise a server that times out, refuses or gives a reply
// that is not usable is passed over for the next. When every server
// refused, the error says so, and when they are the root servers it is
// ErrIntercepted.
// ErrIntercepted. When the root servers gave no usable reply otherwise,
// it is ErrNoRootServerAnswered.
func (r *Resolver) queryServers(
ctx context.Context,
servers []string,
@@ -352,6 +353,10 @@ func (r *Resolver) queryServers(
)
}
if zone == "." {
return nil, fmt.Errorf("%w: %w", ErrNoRootServerAnswered, lastErr)
}
return nil, fmt.Errorf("all servers failed: %w", lastErr)
}
@@ -528,7 +533,7 @@ func (r *Resolver) resolveNSIterative(
}
domain = dns.Fqdn(domain)
servers := rootServerList()
servers := r.rootServers
zone := "."
for range maxDelegation {
@@ -592,7 +597,7 @@ func (r *Resolver) resolveARecord(
}
hostname = dns.Fqdn(hostname)
servers := rootServerList()
servers := r.rootServers
zone := "."
var withoutAddresses []string
@@ -652,7 +657,7 @@ func (r *Resolver) FindAuthoritativeNameservers(
ctx context.Context,
domain string,
) ([]string, error) {
return r.findAuthoritativeNameservers(ctx, domain, rootServerList())
return r.findAuthoritativeNameservers(ctx, domain, r.rootServers)
}
// findAuthoritativeNameservers is FindAuthoritativeNameservers with each
@@ -1127,7 +1132,7 @@ func (r *Resolver) LookupNS(
}
return r.followDelegation(
ctx, dns.Fqdn(strings.ToLower(domain)), ".", nil, rootServerList(),
ctx, dns.Fqdn(strings.ToLower(domain)), ".", nil, r.rootServers,
)
}