{"record":{"id":"feb037a6b0062bab","repo":"micro/go-micro","slug":"invalid-ip-address-in-ips-list-v","errorCode":null,"errorMessage":"invalid IP address in IPs list: %v","messagePattern":"invalid IP address in IPs list: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/mdns/zone.go","lineNumber":114,"sourceCode":"\n\tif len(ips) == 0 {\n\t\tvar err error\n\t\tips, err = net.LookupIP(trimDot(hostName))\n\t\tif err != nil {\n\t\t\t// Try appending the host domain suffix and lookup again\n\t\t\t// (required for Linux-based hosts)\n\t\t\ttmpHostName := fmt.Sprintf(\"%s%s\", hostName, domain)\n\n\t\t\tips, err = net.LookupIP(trimDot(tmpHostName))\n\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"could not determine host IP addresses for %s\", hostName)\n\t\t\t}\n\t\t}\n\t}\n\tfor _, ip := range ips {\n\t\tif ip.To4() == nil && ip.To16() == nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid IP address in IPs list: %v\", ip)\n\t\t}\n\t}\n\n\treturn &MDNSService{\n\t\tInstance:     instance,\n\t\tService:      service,\n\t\tDomain:       domain,\n\t\tHostName:     hostName,\n\t\tPort:         port,\n\t\tIPs:          ips,\n\t\tTXT:          txt,\n\t\tTTL:          defaultTTL,\n\t\tserviceAddr:  fmt.Sprintf(\"%s.%s.\", trimDot(service), trimDot(domain)),\n\t\tinstanceAddr: fmt.Sprintf(\"%s.%s.%s.\", instance, trimDot(service), trimDot(domain)),\n\t\tenumAddr:     fmt.Sprintf(\"_services._dns-sd._udp.%s.\", trimDot(domain)),\n\t}, nil\n}\n","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/internal/util/mdns/zone.go#L96-L132","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the IPs passed to NewMDNSService and remove/replace entries that are nil or unparseable net.IP values.","Filter the list before calling: keep only ips where ip != nil && (ip.To4() != nil || ip.To16() != nil).","Fix the upstream hostname resolution (hostName) so net.LookupHost / interface enumeration returns valid addresses.","Check container/VM network config (e.g. /etc/hosts entries, docker network) that can inject empty or bogus addresses."],"exampleFix":"// before\nips, _ := net.LookupHost(hostName)\naddrs := make([]net.IP, 0)\nfor _, s := range ips { addrs = append(addrs, net.ParseIP(s)) } // nil possible\nsvc, err := NewMDNSService(instance, service, domain, hostName, port, ttl, addrs)\n\n// after\nvar addrs []net.IP\nfor _, s := range ips {\n    if ip := net.ParseIP(s); ip != nil {\n        addrs = append(addrs, ip)\n    }\n}\nif len(addrs) == 0 {\n    return nil, fmt.Errorf(\"no valid IPs for %s\", hostName)\n}\nsvc, err := NewMDNSService(instance, service, domain, hostName, port, ttl, addrs)","handlingStrategy":"validation","validationCode":"func validIPs(ips []net.IP) bool {\n    for _, ip := range ips {\n        if ip == nil || (ip.To4() == nil && ip.To16() == nil) {\n            return false\n        }\n    }\n    return len(ips) > 0\n}\nif !validIPs(addrs) {\n    return fmt.Errorf(\"refusing to register mDNS: no valid IPs\")\n}\nsvc, err := NewMDNSService(instance, service, domain, host, port, ttl, addrs)","typeGuard":"func isValidIP(ip net.IP) bool {\n    return ip != nil && (ip.To4() != nil || ip.To16() != nil)\n}","tryCatchPattern":"svc, err := NewMDNSService(...)\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid IP address\") {\n        log.Printf(\"bad IP list: %v\", err)\n        return nil // degrade gracefully instead of crashing\n    }\n    return err\n}","preventionTips":["Always parse strings with net.ParseIP and drop nil results before building the IP list.","Filter with ip.To4() != nil || ip.To16() != nil before passing IPs to NewMDNSService.","Log the resolved host IP list at startup so bad entries are visible early.","Validate /etc/hosts and container network config in environments where hostnames resolve oddly."],"tags":["mdns","network","validation","ip-address"],"backgroundTag":"invalid-ip-address","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}