Skip to content

fix: normalize DNS search-domain settings - #3816

Open
He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:fix/dns-ignore-root-search-domain
Open

He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:fix/dns-ignore-root-search-domain

Conversation

@He-Pin

@He-Pin He-Pin commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Motivation

System resolver configuration can use a root marker to indicate that no search suffix is configured. Treat that marker as no suffix, and normalize conventional dotted suffixes before building candidates.

Modification

Normalize both system and explicitly configured search domains: ignore the exact root marker, strip one leading dot from a suffix, and remove exact duplicates in first-occurrence order. Keep explicit empty entries, trailing dots and ndots behavior unchanged. Document the configuration.

Tests

Independent review and JDK 17 focused configuration and resolver-parser tests passed on Scala 2.13.18 and 3.3.9 (14/14 each). The additional leading-dot and deduplication regressions failed on the previous Draft version. Scoped format and DNS page parsing passed. These checks send no DNS traffic; full CI and documentation build have not yet been verified.

References

Netty #18545, independently implemented. Separate from #3796.

Motivation:
System resolver configuration can use the root marker to indicate that
no search suffix is configured, and some inputs prefix valid suffixes
with a dot. Applying these strings verbatim can prevent the intended
lookup. Repeated equivalent entries can repeat the same lookup.

Modification:
Normalize system and explicitly configured DNS search domains once in
the resolver settings. Ignore the exact root marker, remove one leading
dot from other entries and retain the first occurrence of each
normalized string. Preserve empty suffixes, trailing dots and ndots.
Document the behavior and add deterministic configuration tests.

Result:
An optional leading dot does not prevent a configured suffix from being
used, and duplicate suffixes no longer expand the same candidate.
Existing search order for distinct suffixes is unchanged.

Tests:
- JDK 17 focused ScalaTest compiler overlays (Scala 2.13.18 and 3.3.9):
  the three normalization assertions fail on the previous PR head and
  pass after the fix. Two root-marker cases and nine unchanged resolver
  configuration parser cases also pass on each axis.
- Native scalafmt 3.11.5, scoped class-signature comparison and
  git diff --check passed.
- Paradox 0.11.1 standalone parser accepted the changed DNS page.
- Full sbt docs/paradox, validation and MiMa not run in the partial
  offline checkout. No DNS network tests were run.

References:
Refs netty/netty#18545; independently implemented in Pekko.
@He-Pin
He-Pin force-pushed the fix/dns-ignore-root-search-domain branch from a9b50fa to 07a0cb9 Compare November 27, 2026 06:07
@He-Pin He-Pin changed the title fix: ignore the DNS root in search-domain settings fix: normalize DNS search-domain settings Nov 27, 2026
@He-Pin
He-Pin marked this pull request as ready for review November 27, 2026 08:48
@He-Pin
He-Pin requested a review from pjfanning November 27, 2026 08:48
}
// Some resolv.conf providers use the root to indicate that there is no search suffix.
// Keep the first occurrence and preserve explicit empty suffixes and trailing dots.
configured.iterator.filterNot(_ == ".").map(_.stripPrefix(".")).distinct.toList

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edge case: the root marker is filtered before the leading dot is stripped, so an entry of .. gets past the filter and is then turned into .. That leaves the root marker in SearchDomains, and AsyncDnsResolver builds name.. from it, which is what this change is meant to avoid.

It is an unlikely value, but could the root marker be filtered again after the strip, e.g.

configured.iterator.filterNot(_ == ".").map(_.stripPrefix(".")).filterNot(_ == ".").distinct.toList

Keeping the first filter matters, since stripping a plain . would otherwise turn it into an explicit empty entry. A test case with .. in the list would cover it.

leading dot is removed from other search suffixes: `.example.org` is treated as `example.org`.
Identical entries after normalization are used once, in first-occurrence order. An explicitly
empty entry still adds no suffix at its position in that order. Trailing dots and `ndots`
are unchanged.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the comment on search-domains in actor/src/main/resources/reference.conf is not updated, so this normalization is only described here. Could a short note be added there as well (the root marker . is ignored, a leading dot is removed and duplicates are used once)? That comment is where most users will look when setting the value.

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.

2 participants