oneby-wang opened a new pull request, #4814: URL: https://github.com/apache/bookkeeper/pull/4814
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: ```bash 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: ```bash 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 ```bash mvn -pl bookkeeper-server -Dtest=org.apache.bookkeeper.net.DNSTest -DfailIfNoTests=false test ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
