Skip to content

fix(lib/hostlist): attach port to IPv6 addresses resolved from DNS - #758

Open
devteamaegis wants to merge 1 commit into
uber:masterfrom
devteamaegis:fix/hostlist-ipv6-dns-addrs
Open

devteamaegis wants to merge 1 commit into
uber:masterfrom
devteamaegis:fix/hostlist-ipv6-dns-addrs

Conversation

@devteamaegis

Copy link
Copy Markdown

Refs #311

Problem

When a hostlist is configured with dns, the resolver attaches the configured port to every address returned by LookupHost. attachPortIfMissing split each name on : and rejected anything with more than one colon, so a single AAAA record made the whole resolution fail. hostlist.New then returns an error and the component does not start. This is the failure described in #311 for dual-stack clusters.

It is easy to reproduce on current master on any machine where localhost resolves to ::1:

_, err := hostlist.New(hostlist.Config{DNS: "localhost:80"})
// attach port to dns contents: invalid name format: ::1, expected 'host' or 'ip:port'

With this change the same call resolves to [[::1]:80 127.0.0.1:80].

Fix

  • Use net.SplitHostPort to detect names that already carry a port.
  • Use net.JoinHostPort to attach the port, which brackets IPv6 addresses ([2001:db8::10]:7).
  • Names that contain colons but are neither host:port nor an IP (for example a:b:c) are still rejected, so TestAttachPortIfMissingError is unchanged.

Testing

  • New TestAttachPortIfMissingIPv6 fails on master with the error above and passes with the fix.
  • go test -race ./lib/hostlist/... ./lib/hashring/... ./lib/healthcheck/... ./origin/blobclient/... passes.
  • golangci-lint run ./lib/hostlist/... (repo .golangci.yml) reports 0 issues.

Scope

This only fixes the DNS resolution error. StripLocal still collects IPv4 local addresses only, so on an IPv6-only network a build-index node would not strip itself from its neighbor list. I left that out to keep this change small. I can send it as a follow-up if you want it. I have not tested a full dual-stack deployment, so I used "Refs" rather than "Fixes".

This was investigated and written with an AI coding agent (Claude) working on my behalf.

The DNS resolver attaches the configured port to each address returned
by LookupHost. attachPortIfMissing split names on ":" and rejected
anything with more than one colon, so any AAAA record (for example a
dual-stack headless service, or "localhost" resolving to ::1) made the
whole resolution fail, and hostlist.New returned an error at startup.

Use net.SplitHostPort to detect names that already carry a port, and
net.JoinHostPort to attach one, which brackets IPv6 addresses. Names
with colons that are neither "host:port" nor an IP are still rejected.

Refs uber#311

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the IPv6 hostlist DNS resolution changes.

No open issues 🎉

What changed in this PR

This PR fixes hostlist DNS resolution failures when DNS returns IPv6 addresses, addressing the startup failure reported in #311. It does not add full IPv6 support; StripLocal remains unchanged.

Changes:

  • Use net.SplitHostPort and net.JoinHostPort to preserve existing ports and correctly format bare IPv6 addresses while still rejecting malformed names.
  • Add regression coverage for IPv6 addresses, IPv4 addresses, and IPv6 addresses with existing ports.
File Description
lib/​hostlist/​list.go Handle IPv6 addresses when attaching the configured port.
lib/​hostlist/​list_test.go Test mixed IP address formats and preservation of existing ports.

Review effort: Balanced

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants