fix: enforce DNS-first ordering for port and TLS checks #64
Reference in New Issue
Block a user
Delete Branch "fix/issue-58-check-ordering"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
DNS checks now always complete before port or TLS checks begin, ensuring those checks use freshly resolved IP addresses instead of potentially stale ones from a previous cycle.
Problem
Port and TLS checks read IP addresses from state that was populated during the most recent DNS check. If DNS changes between cycles, port/TLS checks may target stale IPs. In particular, when the TLS ticker fired (every 12h), it ran
runTLSCheckswithout refreshing DNS first — meaning TLS checks could use IPs that were up to 12 hours old.Changes
runDNSChecks()from the formerrunDNSAndPortChecks()so DNS resolution can be invoked independently as a prerequisite for any check type.RunOnceuses explicit 3-phase ordering: DNS → ports → TLS. Port checks must complete before TLS because TLS checks only target IPs where port 443 is open.TestDNSRunsBeforePortAndTLSChecks: Verifies that when DNS IPs change between cycles, port and TLS checks pick up the new IPs.Check ordering
RunOnce)closes #58
✅ Review: PASS
Summary
Clean, well-structured fix that enforces DNS-first ordering for port and TLS checks.
What was checked
DNS-first ordering verified in all three execution paths:
RunOnce(): DNS → Ports → TLS (explicit 3-phase)runDNSChecks()→checkAllPorts()→saveState()runDNSChecks()→runTLSChecks()→saveState()Fresh IPs confirmed:
collectIPs()reads fromstate.GetHostnameState()which is updated byrunDNSChecks()viacheckHostname()→SetHostnameState(). Port and TLS checks always see the IPs that DNS just resolved.TLS ticker path: Intentionally runs DNS but not ports. TLS checks filter on port state (from last DNS ticker, ≤1h stale). This is a reasonable trade-off — new IPs get port-checked within 1h on the next DNS ticker.
New test
TestDNSRunsBeforePortAndTLSChecks: Correctly verifies that when DNS IPs change between cycles, both port and TLS checks pick up the new IPs. Uses the established mock infrastructure (consistent with all other watcher tests).README updated per sneak's request — monitoring lifecycle section now documents the DNS-first ordering guarantee.
No test weakening, no config changes, no unrelated changes.
docker build .passes — all tests, lint, and format checks green.