VictoriaMetrics/VictoriaMetrics · error

cannot read directory contents in %q: %w

Error message

cannot read directory contents in %q: %w

What it means

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.

Source

Thrown at lib/backup/fscommon/fscommon.go:41

	dst, err = appendFilesInternal(dst, d)
	if err1 := d.Close(); err1 != nil {
		err = err1
	}
	return dst, err
}

func appendFilesInternal(dst []string, d *os.File) ([]string, error) {
	dir := d.Name()
	dfi, err := d.Stat()
	if err != nil {
		return nil, fmt.Errorf("cannot stat %q: %w", dir, err)
	}
	if !dfi.IsDir() {
		return nil, fmt.Errorf("%q isn't a directory", dir)
	}
	fis, err := d.Readdir(-1)
	if err != nil {
		return nil, fmt.Errorf("cannot read directory contents in %q: %w", dir, err)
	}
	for _, fi := range fis {
		name := fi.Name()
		if name == "." || name == ".." {
			continue
		}
		if isSpecialFile(name) {
			// Do not take into account special files.
			continue
		}
		path := filepath.Join(dir, name)
		if fi.IsDir() {
			// Process directory
			dst, err = AppendFiles(dst, path)
			if err != nil {
				return nil, fmt.Errorf("cannot append files %q: %w", path, err)
			}
			continue

View on GitHub (pinned to 5079fb58f1)

Solutions

  1. Check dmesg / filesystem health (fsck, SMART) for underlying I/O errors.
  2. Retry the operation; transient Readdir failures on network filesystems often clear.
  3. Move data to healthy local storage if corruption is indicated.
  4. Inspect the wrapped %w error for the exact errno.
Defensive patterns

Strategy: retry

Try / catch

files, err := fscommon.AppendFiles(nil, dir)
if err != nil && strings.Contains(err.Error(), "cannot read directory contents") {
    // likely transient I/O error; retry once after a delay
    time.Sleep(time.Second)
    files, err = fscommon.AppendFiles(nil, dir)
}
if err != nil {
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: Failing disk or bad sectors under the data dir; FUSE/NFS timeouts mid-listing; container storage driver issues (e.g. overlayfs errors).

Related errors


AI-assisted analysis of VictoriaMetrics/VictoriaMetrics@5079fb58f1 (2026-09-03). Data as JSON: /api/errors/403b48233d21e3ae. Report an issue: GitHub.