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
+24 -9
View File
@@ -43,10 +43,12 @@ type NameserverResponse struct {
}
// Resolver performs iterative DNS resolution from root servers.
// rootServers are the addresses every walk from the root starts at.
type Resolver struct {
log *slog.Logger
client DNSClient
tcp DNSClient
log *slog.Logger
client DNSClient
tcp DNSClient
rootServers []string
}
// New creates a new Resolver instance for use with uber/fx.
@@ -55,9 +57,10 @@ func New(
params Params,
) (*Resolver, error) {
return &Resolver{
log: params.Logger.Get(),
client: &udpClient{timeout: queryTimeoutDuration},
tcp: &tcpClient{timeout: queryTimeoutDuration},
log: params.Logger.Get(),
client: &udpClient{timeout: queryTimeoutDuration},
tcp: &tcpClient{timeout: queryTimeoutDuration},
rootServers: rootServerList(),
}, nil
}
@@ -65,10 +68,22 @@ func New(
// useful for testing without the fx lifecycle.
func NewFromLogger(log *slog.Logger) *Resolver {
return &Resolver{
log: log,
client: &udpClient{timeout: queryTimeoutDuration},
tcp: &tcpClient{timeout: queryTimeoutDuration},
log: log,
client: &udpClient{timeout: queryTimeoutDuration},
tcp: &tcpClient{timeout: queryTimeoutDuration},
rootServers: rootServerList(),
}
}
// NewWithRootServers creates a Resolver as NewFromLogger does, except
// that every walk from the root starts at servers instead of at the root
// servers. Tests use it to show what dnswatcher does when no root server
// answers, or when something on the network answers in their place.
func NewWithRootServers(log *slog.Logger, servers []string) *Resolver {
r := NewFromLogger(log)
r.rootServers = servers
return r
}
// Method implementations are in iterative.go.