{"record":{"id":"c42060662e8438ca","repo":"prometheus/node_exporter","slug":"unable-to-list-all-threads-for-pid-d-w","errorCode":null,"errorMessage":"unable to list all threads for pid: %d %w","messagePattern":"unable to list all threads for pid: (.+?) %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"collector/processes_linux.go","lineNumber":165,"sourceCode":"\nfunc (c *processCollector) getThreadStates(pid int, pidStat procfs.ProcStat, threadStates map[string]int32) error {\n\tfs, err := procfs.NewFS(procFilePath(path.Join(strconv.Itoa(pid), \"task\")))\n\tif err != nil {\n\t\tif c.isIgnoredError(err) {\n\t\t\tc.logger.Debug(\"file not found when retrieving tasks for pid\", \"pid\", pid, \"err\", err)\n\t\t\treturn nil\n\t\t}\n\t\tc.logger.Debug(\"error reading tasks for pid\", \"pid\", pid, \"err\", err)\n\t\treturn fmt.Errorf(\"error reading task for pid %d: %w\", pid, err)\n\t}\n\n\tt, err := fs.AllProcs()\n\tif err != nil {\n\t\tif c.isIgnoredError(err) {\n\t\t\tc.logger.Debug(\"file not found when retrieving tasks for pid\", \"pid\", pid, \"err\", err)\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\"unable to list all threads for pid: %d %w\", pid, err)\n\t}\n\n\tfor _, thread := range t {\n\t\tif pid == thread.PID {\n\t\t\tthreadStates[pidStat.State]++\n\t\t\tcontinue\n\t\t}\n\t\tthreadStat, err := thread.Stat()\n\t\tif err != nil {\n\t\t\tif c.isIgnoredError(err) {\n\t\t\t\tc.logger.Debug(\"file not found when retrieving stats for thread\", \"pid\", pid, \"threadId\", thread.PID, \"err\", err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tc.logger.Debug(\"error reading stat for thread\", \"pid\", pid, \"threadId\", thread.PID, \"err\", err)\n\t\t\treturn fmt.Errorf(\"error reading stat for pid:%d thread:%d err:%w\", pid, thread.PID, err)\n\t\t}\n\t\tthreadStates[threadStat.State]++\n\t}","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/prometheus/node_exporter/blob/17ddd77c59ba27e1508e9f7894b1e55b44d6aed3/collector/processes_linux.go#L147-L183","documentation":"After opening the task directory, getThreadStates calls fs.AllProcs() on it to list the pid's threads; a non-ignored error is wrapped as 'unable to list all threads for pid: %d'. Note the message omits a colon before %w. This aborts the thread-state accounting for the whole scrape.","triggerScenarios":"AllProcs() on the /proc/<pid>/task filesystem returns an error not classified as ignorable — readdir of the task directory failed with EACCES/EPERM or another non-ENOENT error.","commonSituations":"hidepid or LSM restrictions preventing task directory listing for other users' processes; procfs mount corruption; unusual container runtimes exposing a partial procfs.","solutions":["Read the wrapped cause: for EACCES/EPERM, grant the exporter user access (root, hidepid gid option, or LSM allow rule).","Verify the task directory is listable: ls /proc/<pid>/task as the exporter user.","If the process is exiting during scrape, upgrade node_exporter/procfs — newer code treats vanished entries as ignorable.","Retry the scrape; persistent failures indicate a systematic permission problem, not a race."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// check task dir listing works for the exporter user\nif _, err := os.ReadDir(\"/proc/self/task\"); err != nil {\n    log.Printf(\"task listing broken: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := c.Update(ch); err != nil {\n    if strings.Contains(err.Error(), \"unable to list all threads\") {\n        log.Printf(\"thread enumeration failed for a pid; check task dir permissions: %v\", err)\n        // retry on next scrape\n    }\n}","preventionTips":["Ensure readdir permission on /proc/<pid>/task for the exporter user.","Avoid procfs masking by container runtimes for the task hierarchy.","Upgrade node_exporter/procfs to treat vanishing threads as ignorable errors.","Treat single-scrape failures as transient; alert on persistence."],"tags":["linux","procfs","threads","readdir","permissions","node-exporter"],"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"}