#17625·netty

Failed DnsCacheEntry for a search-domain expanded host shadows a Successful DnsCacheEntry

Author: akilegaspiCreated Sep 25, 2026Updated Sep 28, 2026

Netty Version: 4.1.137, also present in later versions

Expected behavior

When several search domains are configured and negativeTtl > 0, a hostname that does not exist under an earlier search domain but resolves under a later one must keep resolving on every lookup, not only the first one.

Actual behavior

After the first successful lookup, the NXDOMAIN recorded for the earlier search domain is served from the cache for the bare hostname, and resolution fails for negativeTtl seconds. No query is sent during that window, so nothing self-corrects. When the negative entry expires the next lookup succeeds and immediately re-creates it, so the symptom is intermittent — which makes it easy to mistake for flaky upstream DNS.

DnsNameResolver.doResolveAllCached probes each <hostname>.<searchDomain> and breaks on the first one that has any cache entry, then treats what it found as authoritative for the bare hostname — including a cached failure, which it turns into tryFailure(promise, cause). Because returning true makes the caller skip its entire body, the search domain walkthrough in DnsResolveContext.resolve is never constructed, so no later search domain is ever tried.

A negative entry only says that this one permutation does not exist. It says nothing about the bare hostname, nor about any later search domain.

Steps to reproduce

  1. Build a DnsNameResolver with negativeTtl(60), ndots(5), and search domains a.example.com and b.example.com in that order.
  2. Arrange for host.a.example.com to return NXDOMAIN and host.b.example.com to resolve.
  3. resolve("host") — succeeds via host.b.example.com. Both the NXDOMAIN and the address are now cached, under their respective appended names.
  4. resolve("host") again within 60 seconds — fails with failed to resolve host.a.example.com, with no DNS query sent.

Step 4 should return the address from step 3.

Who this affects

Everyone using search domain expansion which possibly has the first expansion failing.

The common precondition is simply: more than one search domain, ndots != 0, negativeTtl > 0, and a name that fails under an earlier domain and resolves under a later one.

Minimal yet complete reproducer code (or URL to code)

doResolveAllCached is package-private and static, so it can be driven directly with a stub DnsCache — no DNS server, channel or event loop required. Seed a failure for host.a.example.com and an address for host.b.example.com, then call it for host with both search domains and ndots 5: it returns true with a failed promise instead of the address.

An executable JUnit regression test is included in the PR referenced below.

Netty version

Reproduced on 4.1.137.Final and on 4.2 (cd967a41cc).

Introduced by ec867b6ee1, "Correct use cache for search domains as well" (#14171, 8 Jul 2024, fixing #14046), which added the search domain probe to doResolveAllCached.

#14171 shipped with one modified test covering only the positive path, which is why this went unnoticed.

JVM version (e.g. java -version)

openjdk 21.0.1. Not JVM-dependent.

OS version (e.g. uname -a)

Reproduced on macOS (Darwin 25.6.0, arm64); originally observed on Linux 5.14 under Kubernetes. Not OS-dependent.


Suggested fix

Break only on a positive entry from the search domain probe, so a cached failure no longer terminates the loop or the resolution: https://github.com/netty/netty/pull/17623

This preserves what #14171 intended and leaves negative caching of the hostname actually being resolved unchanged.

Workarounds

  • negativeTtl(0), at the cost of re-querying the doomed permutations on every lookup.
  • Fully-qualified names with a trailing dot (host.b.example.com.), which skip the search domain ladder entirely.

Issue was drafted with the help of Claude