Skip to content

fix(dns): treat empty DNS response as an error - #7741

Open
aivus wants to merge 2 commits into
louislam:masterfrom
aivus:fix/empty-dns-response-4979
Open

fix(dns): treat empty DNS response as an error#7741
aivus wants to merge 2 commits into
louislam:masterfrom
aivus:fix/empty-dns-response-4979

Conversation

@aivus

@aivus aivus commented Aug 21, 2026

Copy link
Copy Markdown

Summary

In this pull request, the following changes are made:

  • DnsMonitorType.dnsResolve() now throws a descriptive error when the DNS resolver returns an empty array, instead of passing it downstream.

Background: when a hostname exists but has no records of the requested type (e.g. a host that only has a CNAME/A record queried for AAAA), Node's Resolver.resolve() resolves with an empty array rather than throwing ENODATA (documented behaviour: nodejs/node#21795). Previously this surfaced as a DOWN monitor with a confusing empty Records: message. The monitor now reports No AAAA records found for <hostname> (or the relevant record type/hostname).

The Array.isArray guard leaves object-returning types like SOA unaffected, and PTR (reverse lookup) is handled before this check.

Please follow this checklist to avoid unnecessary back and forth (click to expand)
  • ⚠️ If there are Breaking change (a fix or feature that alters existing functionality in a way that could cause issues) I have called them out
  • 🧠 I have disclosed any use of LLMs/AI in this contribution and reviewed all generated content. I understand that I am responsible for and able to explain every line of code I submit.
  • 🔍 Any UI changes adhere to visual style of this project.
  • 🛠️ I have self-reviewed and self-tested my code to ensure it works as expected.
  • 📝 I have commented my code, especially in hard-to-understand areas (e.g., using JSDoc for methods).
  • 🤖 I added or updated automated tests where appropriate.
  • 📄 Documentation updates are included (if applicable).
  • 🧰 Dependency updates are listed and explained.
  • ⚠️ CI passes and is green.

Testing

Added test/backend-test/monitors/test-dns.js covering both the empty-response (throws) and non-empty-response (returns records) cases, using node:test mocks so it does not depend on the network:

✔ dnsResolve() throws when the DNS response is an empty array
✔ dnsResolve() returns records when the DNS response is not empty

🤖 Generated with Claude Code


Re-creation of #7598 due to the fact that PR is stuck on GH side

When a hostname exists but has no records of the requested type (e.g. a
host with only a CNAME/A record queried for AAAA), Node's resolver
resolves with an empty array instead of throwing ENODATA. This produced a
confusing empty "Records:" heartbeat message and a DOWN status with no
useful information.

Throw a descriptive error when the response is an empty array so the
monitor reports a meaningful failure.

Fixes louislam#4979
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for the PR! If anyone would like to help with testing, run: npx kuma-pr aivus:fix/empty-dns-response-4979 (requires Node.js and Docker)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better handling of empty DNS response

1 participant