micro/go-micro · error

invalid IP address in IPs list: %v

Error message

invalid IP address in IPs list: %v

What it means

NewMDNSService builds an mDNS advertisement and validates every IP address it plans to announce. Each IP must be parseable as either IPv4 (To4() != nil) or IPv6 (To16() != nil). If an entry is neither, the service constructor refuses to build and returns this error instead of advertising a broken zone.

Source

Thrown at internal/util/mdns/zone.go:114

	if len(ips) == 0 {
		var err error
		ips, err = net.LookupIP(trimDot(hostName))
		if err != nil {
			// Try appending the host domain suffix and lookup again
			// (required for Linux-based hosts)
			tmpHostName := fmt.Sprintf("%s%s", hostName, domain)

			ips, err = net.LookupIP(trimDot(tmpHostName))

			if err != nil {
				return nil, fmt.Errorf("could not determine host IP addresses for %s", hostName)
			}
		}
	}
	for _, ip := range ips {
		if ip.To4() == nil && ip.To16() == nil {
			return nil, fmt.Errorf("invalid IP address in IPs list: %v", ip)
		}
	}

	return &MDNSService{
		Instance:     instance,
		Service:      service,
		Domain:       domain,
		HostName:     hostName,
		Port:         port,
		IPs:          ips,
		TXT:          txt,
		TTL:          defaultTTL,
		serviceAddr:  fmt.Sprintf("%s.%s.", trimDot(service), trimDot(domain)),
		instanceAddr: fmt.Sprintf("%s.%s.%s.", instance, trimDot(service), trimDot(domain)),
		enumAddr:     fmt.Sprintf("_services._dns-sd._udp.%s.", trimDot(domain)),
	}, nil
}

View on GitHub (pinned to 24529f1404)

Solutions

  1. Inspect the IPs passed to NewMDNSService and remove/replace entries that are nil or unparseable net.IP values.
  2. Filter the list before calling: keep only ips where ip != nil && (ip.To4() != nil || ip.To16() != nil).
  3. Fix the upstream hostname resolution (hostName) so net.LookupHost / interface enumeration returns valid addresses.
  4. Check container/VM network config (e.g. /etc/hosts entries, docker network) that can inject empty or bogus addresses.

Example fix

// before
ips, _ := net.LookupHost(hostName)
addrs := make([]net.IP, 0)
for _, s := range ips { addrs = append(addrs, net.ParseIP(s)) } // nil possible
svc, err := NewMDNSService(instance, service, domain, hostName, port, ttl, addrs)

// after
var addrs []net.IP
for _, s := range ips {
    if ip := net.ParseIP(s); ip != nil {
        addrs = append(addrs, ip)
    }
}
if len(addrs) == 0 {
    return nil, fmt.Errorf("no valid IPs for %s", hostName)
}
svc, err := NewMDNSService(instance, service, domain, hostName, port, ttl, addrs)
Defensive patterns

Strategy: validation

Validate before calling

func validIPs(ips []net.IP) bool {
    for _, ip := range ips {
        if ip == nil || (ip.To4() == nil && ip.To16() == nil) {
            return false
        }
    }
    return len(ips) > 0
}
if !validIPs(addrs) {
    return fmt.Errorf("refusing to register mDNS: no valid IPs")
}
svc, err := NewMDNSService(instance, service, domain, host, port, ttl, addrs)

Type guard

func isValidIP(ip net.IP) bool {
    return ip != nil && (ip.To4() != nil || ip.To16() != nil)
}

Try / catch

svc, err := NewMDNSService(...)
if err != nil {
    if strings.Contains(err.Error(), "invalid IP address") {
        log.Printf("bad IP list: %v", err)
        return nil // degrade gracefully instead of crashing
    }
    return err
}

Prevention

When it happens

Trigger: Calling NewMDNSService (directly or via Register) after collecting host IPs where the ips slice contains a zero-value net.IP (nil), an empty string parsed to a nil IP, or a malformed address that failed to parse upstream but was still appended to the list.

Common situations: Hostname resolution returning empty/invalid entries, environment misconfiguration (e.g. hostName resolving to nothing so a placeholder or nil IP was appended), or hand-constructed IP lists in tests like TestNewMDNSService_BadParams feeding bad values.

Related errors


AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01). Data as JSON: /api/errors/feb037a6b0062bab. Report an issue: GitHub.