Repository navigation
fix(lib/hostlist): attach port to IPv6 addresses resolved from DNS - #758
Open
devteamaegis wants to merge 1 commit into
Open
devteamaegis wants to merge 1 commit into
devteamaegis wants to merge 1 commit into
Conversation
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
Contributor
There was a problem hiding this comment.
🟢 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.SplitHostPortandnet.JoinHostPortto 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #311
Problem
When a hostlist is configured with
dns, the resolver attaches the configured port to every address returned byLookupHost.attachPortIfMissingsplit each name on:and rejected anything with more than one colon, so a single AAAA record made the whole resolution fail.hostlist.Newthen 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
masteron any machine wherelocalhostresolves to::1:With this change the same call resolves to
[[::1]:80 127.0.0.1:80].Fix
net.SplitHostPortto detect names that already carry a port.net.JoinHostPortto attach the port, which brackets IPv6 addresses ([2001:db8::10]:7).host:portnor an IP (for examplea:b:c) are still rejected, soTestAttachPortIfMissingErroris unchanged.Testing
TestAttachPortIfMissingIPv6fails onmasterwith 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.
StripLocalstill 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.