Skip to content

fix(lib/hostlist): strip local machine when listed by IP address - #702

Open
taekop wants to merge 1 commit into
uber:masterfrom
taekop:fix/hostlist-strip-local-ip
Open

taekop wants to merge 1 commit into
uber:masterfrom
taekop:fix/hostlist-strip-local-ip

Conversation

@taekop

@taekop taekop commented Oct 6, 2026

Copy link
Copy Markdown

Fixes #699

getLocalNames parsed each interface address with net.ParseIP(addr.String()). net.Interface.Addrs() returns *net.IPNet, whose String() is CIDR (127.0.0.1/8), so the parse returned nil and every local IP was skipped. Only the hostname ended up in the set, and a build-index listed by IP did not strip itself.

This reads the IP from the *net.IPNet / *net.IPAddr value instead. IPv6 addresses are still skipped by the existing To4() check.

Note: the old comment said "non-loopback ips", but the code never filtered loopback. With this change loopback addresses are included, so a 127.0.0.1:<port> entry for the same port is stripped too. I updated the comment to match. Happy to skip loopback instead if that was the intent.

Tested on macOS:

  • go test -race --tags unit ./lib/hostlist/... ./build-index/... passes
  • new TestStripLocalRemovesLocalIP fails on main (127.0.0.1:80 is kept) and passes with the fix
  • golangci-lint run ./lib/hostlist/...: 0 issues

Interface addresses come back as *net.IPNet, whose String() is in CIDR
notation, so net.ParseIP returned nil and every local IP was skipped.
Read the IP from the address value instead.
@CLAassistant

CLAassistant commented Oct 6, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

Host lists do not remove local machine when listed by IP address

2 participants