Skip to content

Avoid PTR lookup for loopback DNS resolution#4814

Open
oneby-wang wants to merge 1 commit into
apache:masterfrom
oneby-wang:fix-loopback-ptr-dns-timeout
Open

Avoid PTR lookup for loopback DNS resolution#4814
oneby-wang wants to merge 1 commit into
apache:masterfrom
oneby-wang:fix-loopback-ptr-dns-timeout

Conversation

@oneby-wang

Copy link
Copy Markdown

Descriptions of the changes in this PR:

Motivation

BookKeeper's DNS.reverseDns currently performs a DNS PTR lookup for IPv4 loopback addresses such as 127.0.0.1. A loopback address is local-only, so asking an external DNS server for 1.0.0.127.in-addr.arpa is unnecessary and can add avoidable network cost.

This also makes local tests depend on router-specific DNS behavior. Some DNS servers return NXDOMAIN quickly for this PTR query, for example:

dig -x 127.0.0.1 @8.8.8.8

However, some home routers do not return a standard DNS response for the same query:

dig -x 127.0.0.1 @192.168.1.1
# connection timed out; no servers could be reached

dig +tcp -x 127.0.0.1 @192.168.1.1
# communications error: end of file

In that environment, ordinary DNS resolution still works, for example dig @192.168.1.1 google.com succeeds. The issue is specific to reverse lookup of the loopback PTR record.

I encountered this while running Pulsar's broker AuditorLedgerCheckerTest, which starts multiple local BookKeeper bookies. The local bookie startup path tried to resolve the loopback interface address, the router DNS timed out on the PTR query for 127.0.0.1, and the test could not start. Switching DNS to 8.8.8.8 made the test start again because that resolver returns quickly.

Since loopback addresses are not externally meaningful, BookKeeper should not query external DNS for their PTR records. It can return the already cached local hostname, matching the existing fallback used by DNS.getHosts when no hostname can be determined.

Changes

  • Skip PTR lookup in DNS.reverseDns when the IPv4 address is loopback.
  • Return the cached local hostname for IPv4 loopback addresses.
  • Extract the PTR lookup call into getPtrAttributes so the DNS query layer can be mocked in tests.
  • Add DNSTest coverage that simulates a DNS timeout and verifies 127.0.0.1 does not call the PTR lookup path.

Tests

mvn -pl bookkeeper-server -Dtest=org.apache.bookkeeper.net.DNSTest -DfailIfNoTests=false test

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.

1 participant