{"record":{"id":"f95963d08b8a9b11","repo":"prometheus/node_exporter","slug":"failed-to-open-proc-self-w-f95963","errorCode":null,"errorMessage":"failed to open /proc/self: %w","messagePattern":"failed to open /proc/self: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/netstat_linux.go","lineNumber":69,"sourceCode":"func init() {\n\tregisterCollector(\"netstat\", defaultEnabled, NewNetStatCollector)\n}\n\n// NewNetStatCollector takes and returns\n// a new Collector exposing network stats.\nfunc NewNetStatCollector(logger *slog.Logger) (Collector, error) {\n\tpattern := regexp.MustCompile(*netStatFields)\n\tfs, err := procfs.NewFS(*procPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open procfs: %w\", err)\n\t}\n\n\t// Network statistics in /proc/net are network namespace local. Reading\n\t// them via the current process' /proc/self/net keeps the same semantics\n\t// while allowing the use of the procfs parsers.\n\tproc, err := fs.Self()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open /proc/self: %w\", err)\n\t}\n\n\treturn &netStatCollector{\n\t\tproc:         proc,\n\t\tfieldPattern: pattern,\n\t\tlogger:       logger,\n\t}, nil\n}\n\nfunc (c *netStatCollector) Update(ch chan<- prometheus.Metric) error {\n\tnetStats, err := c.proc.Netstat()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"couldn't get netstats: %w\", err)\n\t}\n\tsnmpStats, err := c.proc.Snmp()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"couldn't get SNMP stats: %w\", err)\n\t}","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/netstat_linux.go#L51-L87","documentation":"After opening procfs, NewNetStatCollector calls fs.Self() to obtain a handle on /proc/self so netstat data is read from the current process's network namespace. If procfs cannot resolve /proc/self, the constructor returns this wrapped error and the collector fails to initialize.","triggerScenarios":"fs.Self() fails when /proc/self cannot be read or resolved, e.g. /proc is mounted but lacks the self symlink, or the process's procfs entries are hidden/unreadable (hidepid, restricted containers).","commonSituations":"Containers mounting a partial /proc; hidepid=2 proc mounts restricting access; chroot/minimal images without a fully populated procfs.","solutions":["Ensure /proc/self exists and is readable by the exporter process (ls -l /proc/self).","Check proc mount options; relax hidepid or run the exporter with sufficient privileges.","In containers, mount a full /proc rather than a partial subset.","Verify with --path.procfs that the configured procfs root actually contains the self entry."],"exampleFix":"// before\nproc, err := fs.Self()\nif err != nil {\n\treturn nil, fmt.Errorf(\"failed to open /proc/self: %w\", err)\n}\n// after (add path context for debugging)\nproc, err := fs.Self()\nif err != nil {\n\treturn nil, fmt.Errorf(\"failed to open /proc/self under %q (check hidepid/container proc mount): %w\", *procPath, err)\n}","handlingStrategy":"validation","validationCode":"import \"os\"\n// Ensure /proc/self is resolvable under the configured procfs root:\nif _, err := os.Stat(*procPath + \"/self\"); err != nil {\n\t// /proc/self missing: check proc mount completeness/hidepid before init\n}","typeGuard":"null","tryCatchPattern":"// Constructor-time handling: fail fast with actionable context\nif _, err := NewNetStatCollector(logger); err != nil {\n\tif strings.Contains(err.Error(), \"/proc/self\") {\n\t\tlogger.Error(\"procfs self-entry unreadable; check hidepid and container mounts\", \"err\", err)\n\t}\n\treturn err\n}","preventionTips":["Avoid hidepid=2 on hosts running node_exporter, or grant access via supplementary groups.","Mount a complete /proc in containers, not a partial directory tree.","Verify /proc/self resolves at startup (readlink /proc/self).","Use the same mount namespace for the exporter and the procfs it reads."],"tags":["linux","procfs","netstat","filesystem","containers"],"backgroundTag":"file-open-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"}