{"record":{"id":"4711a0bd1c623d3c","repo":"prometheus/node_exporter","slug":"getifaddrs-failed","errorCode":null,"errorMessage":"getifaddrs() failed","messagePattern":"getifaddrs\\(\\) failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/netdev_bsd.go","lineNumber":38,"sourceCode":"\t\"log/slog\"\n)\n\n/*\n#cgo CFLAGS: -D_IFI_OQDROPS\n#include <stdio.h>\n#include <sys/types.h>\n#include <sys/socket.h>\n#include <ifaddrs.h>\n#include <net/if.h>\n*/\nimport \"C\"\n\nfunc getNetDevStats(filter *deviceFilter, logger *slog.Logger) (netDevStats, error) {\n\tnetDev := netDevStats{}\n\n\tvar ifap, ifa *C.struct_ifaddrs\n\tif C.getifaddrs(&ifap) == -1 {\n\t\treturn nil, errors.New(\"getifaddrs() failed\")\n\t}\n\tdefer C.freeifaddrs(ifap)\n\n\tfor ifa = ifap; ifa != nil; ifa = ifa.ifa_next {\n\t\tif ifa.ifa_addr.sa_family != C.AF_LINK {\n\t\t\tcontinue\n\t\t}\n\n\t\tdev := C.GoString(ifa.ifa_name)\n\t\tif filter.ignored(dev) {\n\t\t\tlogger.Debug(\"Ignoring device\", \"device\", dev)\n\t\t\tcontinue\n\t\t}\n\n\t\tdata := (*C.struct_if_data)(ifa.ifa_data)\n\n\t\tnetDev[dev] = map[string]uint64{\n\t\t\t\"receive_packets\":    uint64(data.ifi_ipackets),","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/netdev_bsd.go#L20-L56","documentation":"On BSD platforms the netdev collector enumerates network interfaces via the C getifaddrs() libc call. If getifaddrs returns -1 (it failed to allocate memory or could not read the kernel interface table), getNetDevStats returns this error immediately and the netdev scrape fails. It is a raw wrapper over the errno reported by the libc call.","triggerScenarios":"getNetDevStats invokes `C.getifaddrs(&ifap)` and it returns -1. This happens when the process cannot allocate memory for the interface list, the syscall is blocked (sandbox/seccomp/capability restrictions), or the kernel's network interface table cannot be read (e.g. during heavy interface churn or in restricted jails).","commonSituations":"Running node_exporter inside a jail/container on FreeBSD/OpenBSD with restricted sysctls; memory exhaustion at scrape time; hardened sandboxing (capsicum, pledge, seccomp-like filters) that blocks getifaddrs; transient kernel states on systems with thousands of interfaces being created/destroyed.","solutions":["Check the process sandbox: run outside a restricted jail or grant the needed privileges so getifaddrs can enumerate interfaces.","Verify memory availability at scrape time (the call mallocs the full interface list); raise limits if the host has thousands of interfaces.","Retry the scrape — if it's transient interface churn, the next scrape usually succeeds.","If the platform genuinely blocks it (e.g. minimal sandbox image), disable the netdev collector via `--collector.disable-defaults` + selective enables."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-flight: ensure the process can enumerate interfaces before enabling netdev on BSD\n// (no direct Go pre-check; probe with a syscall-free check is not possible, but you can\n// verify sandbox allows lib libc getifaddrs by running `ifconfig -a` in the same sandbox)\n// shell: ifconfig -a >/dev/null 2>&1 || echo 'interface enumeration blocked'","typeGuard":null,"tryCatchPattern":"stats, err := getNetDevStats(filter, logger)\nif err != nil && strings.Contains(err.Error(), \"getifaddrs() failed\") {\n    // transient churn or sandbox restriction; back off and retry once\n    time.Sleep(100 * time.Millisecond)\n    if stats, err = getNetDevStats(filter, logger); err != nil {\n        logger.Warn(\"netdev scrape failed: getifaddrs unavailable\", \"err\", err)\n    }\n}","preventionTips":["Run the exporter outside restricted jails/sandboxes (capsicum, pledge) or grant needed privileges.","Confirm `ifconfig -a` works as the same user in the same sandbox before deploying.","Watch host memory: getifaddrs allocates the full interface list; huge interface counts need headroom.","Treat single failed scrapes as transient; alert only on sustained netdev collector failures."],"tags":["bsd","network","cgo","netdev"],"backgroundTag":"getifaddrs-failed","analyzedSha":"17ddd77c59ba27e1508e9f7894b1e55b44d6aed3","analyzedAt":"2026-09-07T17:54:06.211Z","contentChangedAt":"2026-09-07T17:54:06.211Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}