{"record":{"id":"70e044daf0cf4cab","repo":"jeessy2/ddns-go","slug":"s-v-70e044","errorCode":null,"errorMessage":"获取网卡 %s 地址失败: %v","messagePattern":"获取网卡 (.+?) 地址失败: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"util/http_client_util.go","lineNumber":105,"sourceCode":"var insecureSkipVerify bool\n\n// CreateHTTPClient Create Default HTTP Client\nfunc CreateHTTPClient() *http.Client {\n\treturn &http.Client{\n\t\tTimeout:   30 * time.Second,\n\t\tTransport: defaultTransport,\n\t}\n}\n\n// GetLocalAddrFromInterface 根据网卡名称获取本地IP地址\nfunc GetLocalAddrFromInterface(ifaceName string) (string, error) {\n\tiface, err := net.InterfaceByName(ifaceName)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"找不到网卡 %s: %v\", ifaceName, err)\n\t}\n\taddrs, err := iface.Addrs()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"获取网卡 %s 地址失败: %v\", ifaceName, err)\n\t}\n\tfor _, addr := range addrs {\n\t\tif ipNet, ok := addr.(*net.IPNet); ok && ipNet.IP.IsGlobalUnicast() {\n\t\t\treturn ipNet.IP.String(), nil\n\t\t}\n\t}\n\treturn \"\", fmt.Errorf(\"网卡 %s 没有可用的单播地址\", ifaceName)\n}\n\n// CreateHTTPClientWithInterface 创建绑定指定网卡的HTTP客户端\nfunc CreateHTTPClientWithInterface(ifaceName string) *http.Client {\n\tif ifaceName == \"\" {\n\t\treturn CreateHTTPClient()\n\t}\n\tlocalIP, err := GetLocalAddrFromInterface(ifaceName)\n\tif err != nil {\n\t\tLog(\"绑定网卡失败, 将使用默认网卡. 网卡: %s, 错误: %v\", ifaceName, err)\n\t\treturn CreateHTTPClient()","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/jeessy2/ddns-go/blob/5874c2e6667c69357ab95079421131104bd3fcae/util/http_client_util.go#L87-L123","documentation":"GetLocalAddrFromInterface calls iface.Addrs() to enumerate the interface's addresses; if the OS returns an error at that point this error ('failed to get addresses for interface <name>') wraps it. This happens after the interface was found, so it indicates a system-level failure retrieving the address list rather than a bad name.","triggerScenarios":"Calling GetLocalAddrFromInterface/CreateHTTPClientWithInterface when net.Interface.Addrs() fails — e.g. permission issues reading interface data, netlink/socket errors, or the interface disappearing between the name lookup and the address query (hot-unplug, container teardown).","commonSituations":"Restricted containers/seccomp setups blocking netlink operations; NIC removed/rename raced with the lookup; kernel or network namespace issues; rare transient OS errors.","solutions":["Retry the call — this is often transient (interface state changed momentarily)","Verify the interface still exists and the process has permission to read network state","Check for seccomp/AppArmor/container policies restricting netlink socket usage","If persistent, recreate the network namespace/interface or restart networking on the host"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"func canReadAddrs(name string) error {\n\tiface, err := net.InterfaceByName(name)\n\tif err != nil { return err }\n\t_, err = iface.Addrs()\n\treturn err\n}\n// if err != nil, retry with backoff before creating the client","typeGuard":null,"tryCatchPattern":"var client *http.Client\nvar err error\nfor i := 0; i < 3; i++ {\n\tif _, err = util.GetLocalAddrFromInterface(ifaceName); err == nil {\n\t\tclient = util.CreateHTTPClientWithInterface(ifaceName)\n\t\tbreak\n\t}\n\ttime.Sleep(time.Duration(1<<i) * 100 * time.Millisecond)\n}\nif err != nil {\n\tlog.Printf(\"giving up binding to %s: %v; using default client\", ifaceName, err)\n\tclient = util.CreateHTTPClient()\n}","preventionTips":["Treat Addrs() failures as transient and retry with backoff","Verify container/seccomp policies permit netlink socket operations","Re-verify the interface still exists if the error persists (it may have been unplugged/renamed)"],"tags":["network","interface-binding","go","os-error"],"backgroundTag":"interface-address-lookup-failed","analyzedSha":"5874c2e6667c69357ab95079421131104bd3fcae","analyzedAt":"2026-09-03T15:41:16.799Z","contentChangedAt":"2026-09-03T15:41:16.799Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}