hashicorp/nomad · error
error creating task %q dir: %w
Error message
error creating task %q dir: %w
What it means
During Move, when the previous allocation has a task-local directory, the new task directory is created with os.MkdirAll before renaming the local dir in. If MkdirAll fails (permissions, disk full, path conflicts), Move returns 'error creating task %q dir'. The migration is aborted for safety.
Source
Thrown at client/allocdir/alloc_dir.go:308
dataDir := filepath.Join(a.SharedDir, SharedDataDir)
if fileInfo, err := os.Stat(otherDataDir); fileInfo != nil && err == nil {
os.Remove(dataDir) // remove an empty data dir if it exists
if err := os.Rename(otherDataDir, dataDir); err != nil {
return fmt.Errorf("error moving data dir: %w", err)
}
}
// Move the task directories
for _, task := range tasks {
otherTaskDir := filepath.Join(other.AllocDirPath(), task.Name)
otherTaskLocal := filepath.Join(otherTaskDir, TaskLocal)
fileInfo, err := os.Stat(otherTaskLocal)
if fileInfo != nil && err == nil {
// TaskDirs haven't been built yet, so create it
newTaskDir := filepath.Join(a.AllocDir, task.Name)
if err := os.MkdirAll(newTaskDir, fileMode777); err != nil {
return fmt.Errorf("error creating task %q dir: %w", task.Name, err)
}
localDir := filepath.Join(newTaskDir, TaskLocal)
os.Remove(localDir) // remove an empty local dir if it exists
if err := os.Rename(otherTaskLocal, localDir); err != nil {
return fmt.Errorf("error moving task %q local dir: %w", task.Name, err)
}
}
}
return nil
}
// Destroy tears down previously build directory structure.
func (a *AllocDir) Destroy() error {
// Unmount all mounted shared alloc dirs.
mErr := new(multierror.Error)
if err := a.UnmountAll(); err != nil {
mErr = multierror.Append(mErr, err)View on GitHub (pinned to 482b49bf1a)
Solutions
- Fix permissions on the target alloc dir
- Free disk space / resolve quota pressure
- Remove the conflicting non-directory path at a.AllocDir/task.Name
- Retry migration after the filesystem issue is resolved
Defensive patterns
Strategy: validation
Validate before calling
if st, err := os.Stat(targetTaskDir); err == nil && !st.IsDir() {
return fmt.Errorf("%s exists and is not a directory", targetTaskDir)
} Try / catch
if err := allocDir.Move(other, tasks); err != nil && strings.Contains(err.Error(), "error creating task") {
// check disk space and permissions on alloc dir before retrying
} Prevention
- Monitor node disk space/quota before mass migrations
- Clean stale alloc dirs to avoid name collisions
- Keep alloc dir permissions consistent across node re-provisioning
When it happens
Trigger: os.MkdirAll(a.AllocDir/task.Name, 0777) fails — target alloc dir read-only, disk full, a file exists where the directory should be, or parent dir missing/permission-denied.
Common situations: Disk quota exhaustion on nodes with many migrations; leftover files named like task dirs from corrupted prior runs; permissions changed by external tooling; read-only mounts after node incidents.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- error creating directory: %w
- plugin not executable
- failed to snapshot %s: %w
- unable to move to %q - alloc dir is not built
- error moving data dir: %w
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/5096390a8c55b0db.
Report an issue: GitHub.