{"record":{"id":"d21832515ceb11ce","repo":"prometheus/node_exporter","slug":"failed-to-get-ipv4-sockstat-data-w","errorCode":null,"errorMessage":"failed to get IPv4 sockstat data: %w","messagePattern":"failed to get IPv4 sockstat data: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/sockstat_linux.go","lineNumber":61,"sourceCode":"// NewSockStatCollector returns a new Collector exposing socket stats.\nfunc NewSockStatCollector(logger *slog.Logger) (Collector, error) {\n\treturn &sockStatCollector{logger}, nil\n}\n\nfunc (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error {\n\tfs, err := procfs.NewFS(*procPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open procfs: %w\", err)\n\t}\n\n\t// If IPv4 and/or IPv6 are disabled on this kernel, handle it gracefully.\n\tstat4, err := fs.NetSockstat()\n\tswitch {\n\tcase err == nil:\n\tcase errors.Is(err, os.ErrNotExist):\n\t\tc.logger.Debug(\"IPv4 sockstat statistics not found, skipping\")\n\tdefault:\n\t\treturn fmt.Errorf(\"failed to get IPv4 sockstat data: %w\", err)\n\t}\n\n\tstat6, err := fs.NetSockstat6()\n\tswitch {\n\tcase err == nil:\n\tcase errors.Is(err, os.ErrNotExist):\n\t\tc.logger.Debug(\"IPv6 sockstat statistics not found, skipping\")\n\tdefault:\n\t\treturn fmt.Errorf(\"failed to get IPv6 sockstat data: %w\", err)\n\t}\n\n\tstats := []struct {\n\t\tisIPv6 bool\n\t\tstat   *procfs.NetSockstat\n\t}{\n\t\t{\n\t\t\tstat: stat4,\n\t\t},","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/sockstat_linux.go#L43-L79","documentation":"After opening procfs, the sockstat collector reads /proc/net/sockstat via fs.NetSockstat(). Errors other than os.ErrNotExist are wrapped as 'failed to get IPv4 sockstat data'. A missing file is tolerated (IPv4 disabled kernels log and skip); anything else is a real read/parse failure.","triggerScenarios":"fs.NetSockstat() returning a non-ErrNotExist error during Update: permission problems reading /proc/net/sockstat or procfs parse errors on unexpected content.","commonSituations":"Hardened/seccomp environments blocking /proc/net reads; LSM policies denying access; kernels or LSMs returning unexpected sockstat content that procfs cannot parse.","solutions":["Grant the exporter process read access to /proc/net/sockstat (check seccomp/AppArmor/SELinux denials)","Confirm /proc/net/sockstat is readable by the exporter user: `cat /proc/net/sockstat`","Update github.com/prometheus/procfs if the kernel format changed; disable the sockstat collector as a last resort"],"exampleFix":"// verify access as the exporter user\nsudo -u node_exporter cat /proc/net/sockstat\n// if denied, adjust the LSM profile or run the exporter with sufficient privileges","handlingStrategy":"try-catch","validationCode":"// pre-check before scraping IPv4 sockstat\nif _, err := os.Stat(\"/proc/net/sockstat\"); os.IsPermission(err) {\n\t// environment blocks the file; expect this error or skip the collector\n}","typeGuard":null,"tryCatchPattern":"if err := collector.Update(ch); err != nil {\n\tif strings.Contains(err.Error(), \"failed to get IPv4 sockstat data\") {\n\t\tlogger.Warn(\"IPv4 sockstat unavailable\", \"err\", err)\n\t} else {\n\t\treturn err\n\t}\n}","preventionTips":["Ensure the exporter user can read /proc/net/sockstat; review seccomp/AppArmor/SELinux denials","In containers, avoid masking /proc/net entries via lxcfs or similar without testing","Note ErrNotExist is tolerated (IPv4 disabled); only fix genuine permission/parse errors"],"tags":["procfs","network","linux","sockstat"],"backgroundTag":"file-read-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"}