{"record":{"id":"a0ae5c8a0aeb8217","repo":"micro/go-micro","slug":"could-not-determine-host-v","errorCode":null,"errorMessage":"could not determine host: %v","messagePattern":"could not determine host: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/mdns/zone.go","lineNumber":89,"sourceCode":"\t}\n\tif port == 0 {\n\t\treturn nil, fmt.Errorf(\"missing service port\")\n\t}\n\n\t// Set default domain\n\tif domain == \"\" {\n\t\tdomain = \"local.\"\n\t}\n\tif err := validateFQDN(domain); err != nil {\n\t\treturn nil, fmt.Errorf(\"domain %q is not a fully-qualified domain name: %v\", domain, err)\n\t}\n\n\t// Get host information if no host is specified.\n\tif hostName == \"\" {\n\t\tvar err error\n\t\thostName, err = os.Hostname()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"could not determine host: %v\", err)\n\t\t}\n\t\thostName = fmt.Sprintf(\"%s.\", hostName)\n\t}\n\tif err := validateFQDN(hostName); err != nil {\n\t\treturn nil, fmt.Errorf(\"hostName %q is not a fully-qualified domain name: %v\", hostName, err)\n\t}\n\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 {","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/internal/util/mdns/zone.go#L71-L107","documentation":"When hostName is empty, NewMDNSService falls back to os.Hostname() to auto-detect the machine's hostname. If that OS call fails, this error wraps the underlying reason. This is rare and usually indicates a broken system environment rather than a library problem.","triggerScenarios":"Calling NewMDNSService(instance, service, domain, \"\", port, ips, txt) in an environment where os.Hostname() returns an error — e.g. restricted sandbox/container with no UTS namespace access, or a stripped-down runtime lacking /proc/sys/kernel/hostname.","commonSituations":"Minimal Docker/CI containers with unusual security profiles; embedded systems with misconfigured kernels; test sandboxes that stub out hostname lookup.","solutions":["Pass an explicit hostName ending in '.' so os.Hostname() is never called, e.g. \"myhost.local.\"","Check the wrapped %v cause; fix the container/OS hostname configuration (set --hostname / UTS settings)","Pre-compute os.Hostname() yourself and handle the failure with a fallback name before registering"],"exampleFix":"// before\nsvc, err := NewMDNSService(\"myapp\", \"_http._tcp\", \"local.\", \"\", 8080, ips, nil) // relies on os.Hostname()\n// after\nhost, err := os.Hostname()\nif err != nil {\n\thost = \"localhost\"\n}\nsvc, err2 := NewMDNSService(\"myapp\", \"_http._tcp\", \"local.\", host+\".\", 8080, ips, nil)","handlingStrategy":"fallback","validationCode":"host, hostErr := os.Hostname()\nif hostErr != nil {\n\thost = \"localhost\" // or read from config\n}\nhostName := host + \".\"","typeGuard":"func canAutoDetectHost() bool { _, err := os.Hostname(); return err == nil }","tryCatchPattern":"svc, err := NewMDNSService(instance, service, domain, hostName, port, ips, txt)\nif err != nil {\n\tif strings.Contains(err.Error(), \"could not determine host\") {\n\t\treturn fmt.Errorf(\"pass an explicit hostName; os.Hostname() is unavailable in this environment: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Pass an explicit hostName instead of relying on auto-detection in containers/sandboxes","Verify os.Hostname() works at startup when running under restricted runtimes","Configure a fallback hostname in config for ephemeral environments"],"tags":["mdns","hostname","os","environment"],"backgroundTag":"hostname-resolution-failed","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}