hashicorp/nomad · error
error creating file: %w
Error message
error creating file: %w
What it means
During tar extraction, after removing any prior entry, Nomad calls os.Create on the destination file path. This error is returned when file creation fails, typically because the parent directory does not exist or lacks write permission.
Source
Thrown at client/allocwatcher/alloc_watcher.go:653
return fmt.Errorf("error evaluating symlink: %w", err)
} else if escapes {
return fmt.Errorf("archive contains symlink that escapes alloc dir")
}
}
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 aliveView on GitHub (pinned to 482b49bf1a)
Solutions
- Verify the archive contains directory entries before the files inside them
- Check free disk space (ENOSPC) on the destination node
- Fix write permissions/ownership of the alloc dir for the Nomad client user
- Clean stale/partial extraction state and retry the migration
Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight checks before migration: // free disk space (syscall.Statfs) and write access to the destination (os.WriteFile probe)
Try / catch
if err := watcher.Wait(ctx); err != nil {
if strings.Contains(err.Error(), "error creating file") {
if errors.Is(err, syscall.ENOSPC) { alertDiskFull(); return err }
os.RemoveAll(dest)
return retryMigration(ctx, alloc)
}
return err
} Prevention
- Monitor disk space on client nodes and alert before full
- Ensure the client user owns the data/alloc directories
- Pin consistent Nomad versions so archive ordering (dirs before files) matches
When it happens
Trigger: streamAllocDir processes a tar.TypeReg header and os.Create(filepath.Join(dest, hdr.Name)) returns an error (ENOENT missing parent dir, EACCES, ENOSPC).
Common situations: Archive lists a file before its parent directory entry; disk full on the destination node; permission mismatch after running the client as a different user; path collisions with an existing directory.
Related errors
- error removing existing file: %w
- plugin not executable
- Chmod(%v) failed: %w
- Couldn't change owner/group of %v to (uid: %v, gid: %v): %w
- unable to remove existing unix socket: %w
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/413439b9ffcf6e00.
Report an issue: GitHub.