{"record":{"id":"f7a21fa4aba1d968","repo":"hashicorp/nomad","slug":"failed-to-statfs-q-v","errorCode":null,"errorMessage":"failed to Statfs %q: %v","messagePattern":"failed to Statfs %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/lib/nsutil/ns_linux.go","lineNumber":131,"sourceCode":"\tNSFS_MAGIC   = unix.NSFS_MAGIC\n\tPROCFS_MAGIC = unix.PROC_SUPER_MAGIC\n)\n\ntype NSPathNotExistErr struct{ msg string }\n\nfunc (e NSPathNotExistErr) Error() string { return e.msg }\n\ntype NSPathNotNSErr struct{ msg string }\n\nfunc (e NSPathNotNSErr) Error() string { return e.msg }\n\nfunc IsNSorErr(nspath string) error {\n\tstat := syscall.Statfs_t{}\n\tif err := syscall.Statfs(nspath, &stat); err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\terr = NSPathNotExistErr{msg: fmt.Sprintf(\"failed to Statfs %q: %v\", nspath, err)}\n\t\t} else {\n\t\t\terr = fmt.Errorf(\"failed to Statfs %q: %v\", nspath, err)\n\t\t}\n\t\treturn err\n\t}\n\n\tswitch stat.Type {\n\tcase PROCFS_MAGIC, NSFS_MAGIC:\n\t\treturn nil\n\tdefault:\n\t\treturn NSPathNotNSErr{msg: fmt.Sprintf(\"unknown FS magic on %q: %x\", nspath, stat.Type)}\n\t}\n}\n\n// GetNS returns an object representing the namespace referred to by @path\nfunc GetNS(nspath string) (NetNS, error) {\n\terr := IsNSorErr(nspath)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/lib/nsutil/ns_linux.go#L113-L149","documentation":"IsNSorErr validates that a path refers to a namespace file by statfs-ing it and comparing the filesystem magic (PROCFS_MAGIC or NSFS_MAGIC). This error is returned when syscall.Statfs fails on the given path and the path exists — i.e. Statfs failed for a reason other than non-existence, so the path cannot be confirmed as a namespace.","triggerScenarios":"Calling IsNSorErr (directly or via GetNS) with a path that exists but cannot be stat'd: permission denied on a parent directory, path is on a broken mount, I/O error, or too many symbolic links.","commonSituations":"Passing a netns path like /proc/<pid>/ns/net where /proc is not mounted or is mounted with hidepid restrictions; stale bind-mounted ns paths after a container exited (though those usually give NSPathNotExistErr); typo in the path with a dangling mount point.","solutions":["Check the wrapped errno from the %v: EACCES means fix permissions, ENOTDIR/ENOENT means fix the path","Verify /proc is mounted and readable by the calling user","Confirm the path is the correct /proc/<pid>/ns/net or a valid bind mount of a namespace","If os.IsNotExist was the cause, the error would be NSPathNotExistErr instead — treat this variant as an environment/mount problem"],"exampleFix":"// before\nns, err := GetNS(\"/proc/9999/ns/net\") // pid gone, statfs fails\n// after\nif _, err := os.Stat(\"/proc/9999/ns/net\"); err != nil {\n    return fmt.Errorf(\"netns path unavailable: %w\", err)\n}\nns, err := GetNS(\"/proc/9999/ns/net\")","handlingStrategy":"validation","validationCode":"func validateNSPath(p string) error {\n    fi, err := os.Stat(p)\n    if err != nil {\n        return fmt.Errorf(\"netns path missing: %w\", err)\n    }\n    if !fi.Mode().IsRegular() && fi.Mode()&os.ModeDevice == 0 && !fi.Mode().IsDir() {\n        // proceed; ns files are odd modes, only reject obvious dirs\n        _ = fi\n    }\n    return nil\n}","typeGuard":"func isNSPathNotExistErr(err error) bool {\n    _, ok := err.(NSPathNotExistErr)\n    return ok\n}","tryCatchPattern":"if err := IsNSorErr(nspath); err != nil {\n    if isNSPathNotExistErr(err) {\n        return fmt.Errorf(\"netns does not exist: %w\", err)\n    }\n    return fmt.Errorf(\"netns path unusable (check /proc mount & perms): %w\", err)\n}","preventionTips":["Verify /proc is mounted and readable before resolving ns paths","Re-check that the PID owning the namespace is alive","Use canonical paths (/proc/<pid>/ns/net) and fresh bind mounts","Handle NSPathNotExistErr separately from generic Statfs failures"],"tags":["linux","network-namespace","filesystem","statfs"],"backgroundTag":"netns-path-invalid","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}