{"record":{"id":"870f059c74a2fd2e","repo":"Billionmail/BillionMail","slug":"local-ip-not-found","errorCode":null,"errorMessage":"local IP not found","messagePattern":"local IP not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/public/common.go","lineNumber":2202,"sourceCode":"\t\t\tdefer dk.Close()\n\t\t\t// If the local IP starts with 172., it may be a Docker container, so we try to get the host's IP\n\t\t\tres, err := dk.ExecHostShellCommand(context.Background(), \"ip addr | grep -E -o '[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}' | grep -E -v \\\"^127\\\\.|^255\\\\.|^0\\\\.\\\" | head -n 1\")\n\n\t\t\tif err == nil && res != nil {\n\t\t\t\tres.Output = SanitizeIPChars(res.Output)\n\n\t\t\t\tif IsIpAddr(res.Output) {\n\t\t\t\t\tlocalIp = res.Output\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif localIp != \"\" {\n\t\treturn localIp, nil\n\t}\n\n\treturn \"\", errors.New(\"local IP not found\")\n}\n\n// GetServerIPAndLocalIP retrieves the server's public and local IP addresses.\nfunc GetServerIPAndLocalIP() (string, string, error) {\n\tpublicIP, err := GetServerIP()\n\tif err != nil {\n\t\treturn \"\", \"\", err\n\t}\n\n\tlocalIP, err := GetLocalIP()\n\tif err != nil {\n\t\treturn \"\", \"\", err\n\t}\n\n\treturn publicIP, localIP, nil\n}\n\n// Get server port","sourceCodeStart":2184,"sourceCodeEnd":2220,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/public/common.go#L2184-L2220","documentation":"GetLocalIP in core/internal/service/public/common.go tries to determine the machine's local (private) IP address by dialing/inspecting interfaces. If no candidate local IP can be determined, it returns the sentinel error \"local IP not found\". Callers use this to identify which address the host would use for outbound traffic.","triggerScenarios":"Calling GetLocalIP() on a machine with no usable non-loopback network interfaces, in a container/netns with only the loopback interface up, or when interfaces exist but have no IPv4 address bound to them.","commonSituations":"Running in a minimal Docker container without networking configured yet, boot-time code executing before interfaces are up, VMs with networking disabled, or test environments with no network.","solutions":["Bring up a network interface and assign it an address (docker network config, ifup, ip addr add).","For containers, ensure the container joins a user-defined bridge network with an assigned IP.","Fall back to a configurable override (env var or config) for the local IP when auto-detection is impossible.","Retry after network initialization if this runs during startup before interfaces are ready."],"exampleFix":"// before\nlocalIP, err := public.GetLocalIP() // \"local IP not found\" in bare container\n// after\nlocalIP := os.Getenv(\"LOCAL_IP\")\nif localIP == \"\" {\n    localIP, err = public.GetLocalIP()\n    if err != nil {\n        log.Printf(\"auto-detect failed, defaulting to 127.0.0.1: %v\", err)\n        localIP = \"127.0.0.1\"\n    }\n}","handlingStrategy":"fallback","validationCode":"ifaces, _ := net.Interfaces()\nhasIPv4 := false\nfor _, i := range ifaces {\n    if i.Flags&net.FlagUp != 0 && i.Flags&net.FlagLoopback == 0 {\n        addrs, _ := i.Addrs()\n        if len(addrs) > 0 { hasIPv4 = true }\n    }\n}\nif !hasIPv4 { log.Println(\"warning: no non-loopback interface with an address\") }","typeGuard":null,"tryCatchPattern":"localIP, err := public.GetLocalIP()\nif err != nil {\n    if fallback := os.Getenv(\"LOCAL_IP\"); fallback != \"\" {\n        localIP = fallback\n    } else {\n        localIP = \"127.0.0.1\"\n        log.Printf(\"local IP detection failed, using loopback: %v\", err)\n    }\n}","preventionTips":["Support an explicit LOCAL_IP env override for containers and minimal hosts","Delay IP detection until network interfaces are up","In Docker, attach the container to a network with an assigned IP","Test network-dependent code paths in environments without networking"],"tags":["network","ip-detection","environment","go"],"backgroundTag":"local-ip-not-found","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}