hashicorp/nomad · error
could not stat file: %v
Error message
could not stat file: %v
What it means
CopyDir successfully opens a regular file but then calls r.Stat() on the open handle to learn its mode for the destination. If that Stat fails (unexpected filesystem/I-O failure on an already-open handle), the walk aborts with this wrapped error.
Source
Thrown at helper/escapingfs/copydir.go:44
if d.IsDir() {
info, err := d.Info()
if err != nil {
return fmt.Errorf("could not stat directory: %v", err)
}
return os.MkdirAll(newPath, info.Mode())
}
if !d.Type().IsRegular() {
return fmt.Errorf("copying cannot traverse symlinks")
}
r, err := srcFs.Open(oldPath)
if err != nil {
return fmt.Errorf("could not open existing file: %v", err)
}
defer r.Close()
info, err := r.Stat()
if err != nil {
return fmt.Errorf("could not stat file: %v", err)
}
w, err := os.OpenFile(newPath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, info.Mode())
if err != nil {
return err
}
if _, err := io.Copy(w, r); err != nil {
w.Close()
return fmt.Errorf("could not copy file: %v", err)
}
return w.Close()
})
}
View on GitHub (pinned to 482b49bf1a)
Solutions
- Retry the CopyDir; transient network-filesystem failures often resolve
- Check filesystem health (`fsck`, dmesg, mount status) if the error persists
- Avoid copying directly across unstable network mounts — copy locally first or remount the share
- Verify no concurrent process is racing to remove/rename the file during the copy
Example fix
// before $ nomad ... # copy from an NFS mount that dropped // after $ cp -r /mnt/nfs/taskdir /tmp/staging # copy locally first, verify, then CopyDir from staging
Defensive patterns
Strategy: retry
Validate before calling
info, err := os.Stat(path)
if err != nil { return fmt.Errorf("file %s cannot be statted: %w", path, err) } Try / catch
if err := escapingfs.CopyDir(src, dst); err != nil {
if strings.HasPrefix(err.Error(), "could not stat file") {
time.Sleep(500 * time.Millisecond)
return escapingfs.CopyDir(src, dst) // transient FS failures often resolve
}
return err
} Prevention
- Prefer stable local filesystems over network mounts for source directories
- Retry transient I/O errors with backoff
- Check filesystem/mount health if errors recur (dmesg, fsck, remount)
- Avoid concurrent mutation of the source directory during the copy
When it happens
Trigger: CopyDir on a source file whose open file handle cannot be stat'ed — typically OS-level filesystem errors, network filesystems dropping the handle mid-operation, or a race where the file vanishes/changes state right after open.
Common situations: NFS/SMB/network mounts with unstable handles; container overlayfs edge cases; filesystem corruption; extremely rare since the file was just opened successfully.
Related errors
- unable to read rooted allocation directory
- can't seek to offset %d: %w
- Couldn't copy %q to %q: %w
- error writing to file %q: %w
- failed to list entries: %v
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/30001f9442dbcbf1.
Report an issue: GitHub.