{"record":{"id":"403b48233d21e3ae","repo":"VictoriaMetrics/VictoriaMetrics","slug":"cannot-read-directory-contents-in-q-w","errorCode":null,"errorMessage":"cannot read directory contents in %q: %w","messagePattern":"cannot read directory contents in %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/backup/fscommon/fscommon.go","lineNumber":41,"sourceCode":"\tdst, err = appendFilesInternal(dst, d)\n\tif err1 := d.Close(); err1 != nil {\n\t\terr = err1\n\t}\n\treturn dst, err\n}\n\nfunc appendFilesInternal(dst []string, d *os.File) ([]string, error) {\n\tdir := d.Name()\n\tdfi, err := d.Stat()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot stat %q: %w\", dir, err)\n\t}\n\tif !dfi.IsDir() {\n\t\treturn nil, fmt.Errorf(\"%q isn't a directory\", dir)\n\t}\n\tfis, err := d.Readdir(-1)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot read directory contents in %q: %w\", dir, err)\n\t}\n\tfor _, fi := range fis {\n\t\tname := fi.Name()\n\t\tif name == \".\" || name == \"..\" {\n\t\t\tcontinue\n\t\t}\n\t\tif isSpecialFile(name) {\n\t\t\t// Do not take into account special files.\n\t\t\tcontinue\n\t\t}\n\t\tpath := filepath.Join(dir, name)\n\t\tif fi.IsDir() {\n\t\t\t// Process directory\n\t\t\tdst, err = AppendFiles(dst, path)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"cannot append files %q: %w\", path, err)\n\t\t\t}\n\t\t\tcontinue","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/VictoriaMetrics/VictoriaMetrics/blob/5079fb58f1e8e62113f90c945ad71586c797d770/lib/backup/fscommon/fscommon.go#L23-L59","documentation":"Fires in appendFilesInternal when d.Readdir(-1) fails after the directory was successfully opened and stat'ed. The wrapped error indicates the directory listing was interrupted — commonly concurrent deletion of the directory or an I/O error; the input at fault is the already-open directory handle's path.","triggerScenarios":"Readdir on a directory whose entries cannot be read - I/O error on the underlying storage, EINTR-type interruptions, or the directory being mutated concurrently on a flaky filesystem.","commonSituations":"Failing disk or bad sectors under the data dir; FUSE/NFS timeouts mid-listing; container storage driver issues (e.g. overlayfs errors).","solutions":["Check dmesg / filesystem health (fsck, SMART) for underlying I/O errors.","Retry the operation; transient Readdir failures on network filesystems often clear.","Move data to healthy local storage if corruption is indicated.","Inspect the wrapped %w error for the exact errno."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"files, err := fscommon.AppendFiles(nil, dir)\nif err != nil && strings.Contains(err.Error(), \"cannot read directory contents\") {\n    // likely transient I/O error; retry once after a delay\n    time.Sleep(time.Second)\n    files, err = fscommon.AppendFiles(nil, dir)\n}\nif err != nil {\n    return err\n}","preventionTips":["Monitor disk health (SMART, fsck) for the storage holding the data.","Prefer local disks over flaky network mounts for backup sources.","Retry backups on transient I/O failures."],"tags":["filesystem","go","backup","io"],"backgroundTag":"readdir-failed","analyzedSha":"5079fb58f1e8e62113f90c945ad71586c797d770","analyzedAt":"2026-09-03T18:10:26.153Z","contentChangedAt":"2026-09-03T18:10:26.153Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}