hashicorp/nomad · error
error chmoding file %w
Error message
error chmoding file %w
What it means
While streaming the previous allocation's directory as a tar archive in streamAllocDir, f.Chmod on a newly created regular file failed, aborting the migration of the alloc dir to the new node. The file is closed before returning so no descriptor leaks.
Source
Thrown at client/allocwatcher/alloc_watcher.go:659
continue
}
// If the header is a file, we write to a file
if hdr.Typeflag == tar.TypeReg {
fPath := filepath.Join(dest, hdr.Name)
if _, err := os.Lstat(fPath); err == nil {
if err := os.Remove(fPath); err != nil {
return fmt.Errorf("error removing existing file: %w", err)
}
}
f, err := os.Create(fPath)
if err != nil {
return fmt.Errorf("error creating file: %w", err)
}
// Setting the permissions of the file as the origin.
if err := f.Chmod(os.FileMode(hdr.Mode)); err != nil {
f.Close()
return fmt.Errorf("error chmoding file %w", err)
}
// Can't change owner if not root or on Windows.
if euid == 0 {
if err := f.Chown(hdr.Uid, hdr.Gid); err != nil {
f.Close()
return fmt.Errorf("error chowning file %w", err)
}
}
// We write in chunks so that we can test if the client
// is still alive
for !canceled() {
n, err := tr.Read(buf)
if n > 0 && (err == nil || err == io.EOF) {
if _, err := f.Write(buf[:n]); err != nil {
f.Close()
return fmt.Errorf("error writing to file %q: %w", f.Name(), err)View on GitHub (pinned to 482b49bf1a)
Solutions
- Move the Nomad data dir onto a POSIX filesystem (ext4/xfs) instead of FAT/NTFS/network mounts
- Check SELinux/AppArmor audit logs and add allow rules for the Nomad client
- Inspect the archive header Mode values for unsupported bits
- Retry the migration after fixing the destination filesystem
Defensive patterns
Strategy: validation
Validate before calling
// Verify the destination filesystem supports chmod before placing the data dir:
// f, _ := os.Create(probe); err := f.Chmod(0644); if err != nil { filesystem unsupported } Try / catch
if err := watcher.Wait(ctx); err != nil {
if strings.Contains(err.Error(), "error chmoding file") {
// fall back to a fresh alloc without migrating preserved permissions
return startWithoutMigration(ctx, alloc)
}
return err
} Prevention
- Host the Nomad data dir on POSIX-permission filesystems
- Avoid FAT/NTFS/9p mounts for client data dirs
- Review SELinux/AppArmor policies for the Nomad client binary
When it happens
Trigger: os.Create succeeds but f.Chmod(hdr.Mode) returns an error during TypeReg extraction — e.g. read-only or special filesystems rejecting attribute changes, or fd issues.
Common situations: Files created on FAT/NTFS or other filesystems with limited permission support; security modules (SELinux/AppArmor) blocking chmod; unusual mode bits in a hand-crafted archive (e.g. setuid on restricted FS).
Related errors
- Chmod(%v) failed: %w
- plugin not executable
- Couldn't change owner/group of %v to (uid: %v, gid: %v): %w
- unable to remove existing unix socket: %w
- failed to write vault token to secrets dir: %v
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/cbeb89e14cbcddab.
Report an issue: GitHub.